| 1 |
cvsjoko |
1.1 |
<? |
| 2 |
|
|
|
| 3 |
|
|
// =============================================================== |
| 4 |
|
|
class Tracking { |
| 5 |
|
|
|
| 6 |
|
|
// our TrackingState |
| 7 |
|
|
var $state; |
| 8 |
|
|
|
| 9 |
|
|
// a reference to HttpLib |
| 10 |
|
|
var $httplib; |
| 11 |
|
|
|
| 12 |
|
|
// instantiated datastore, some pages might need it |
| 13 |
|
|
var $ds; |
| 14 |
|
|
|
| 15 |
|
|
|
| 16 |
|
|
// some information-clusters (ics) for keeping meta-information |
| 17 |
|
|
var $ic_virtualpages; |
| 18 |
|
|
var $ic_pagetemplates; |
| 19 |
|
|
var $ic_menustructure; |
| 20 |
|
|
var $ic_navigationtargets; |
| 21 |
|
|
|
| 22 |
|
|
// an object-reference to an ic which holds metadata for the current virtual-page being rendered by "$tracking->genArea()" |
| 23 |
|
|
var $ic_virtualpage_current; |
| 24 |
|
|
|
| 25 |
|
|
// misc |
| 26 |
|
|
var $pageargs; |
| 27 |
|
|
|
| 28 |
|
|
|
| 29 |
|
|
// ------------------------------------------------------------------------------------------------ |
| 30 |
|
|
function Tracking() { |
| 31 |
|
|
|
| 32 |
|
|
// we need some information from "Site" |
| 33 |
|
|
global $site; |
| 34 |
|
|
|
| 35 |
|
|
// create objects |
| 36 |
|
|
$this->httplib = new HttpLib(); |
| 37 |
|
|
|
| 38 |
|
|
// initialize information clusters |
| 39 |
|
|
($this->ic_virtualpages = $site->getInformationCluster('virtualpages')) || trigger_error("could not load InformationCluster", E_USER_ERROR); |
| 40 |
|
|
($this->ic_pagetemplates = $site->getInformationCluster('pagetemplates')) || trigger_error("could not load InformationCluster", E_USER_ERROR); |
| 41 |
|
|
($this->ic_menustructure = $site->getInformationCluster('menu_structure')) || trigger_error("could not load InformationCluster", E_USER_ERROR); |
| 42 |
|
|
($this->ic_navigationtargets = $site->getInformationCluster('navigation_targets')) || trigger_error("could not load InformationCluster", E_USER_ERROR); |
| 43 |
|
|
|
| 44 |
|
|
// initialize some class-variables |
| 45 |
|
|
$this->modules_loaded = array(); |
| 46 |
|
|
|
| 47 |
|
|
} |
| 48 |
|
|
|
| 49 |
|
|
|
| 50 |
|
|
// ------------------------------------------------------------------------------------------------ |
| 51 |
|
|
function initState($metadata_tracking_vars, $metadata_tracking_callbacks) { |
| 52 |
|
|
// initialize state |
| 53 |
|
|
$this->state = new TrackingState($metadata_tracking_vars, $metadata_tracking_callbacks); |
| 54 |
|
|
$this->state->collectInputArguments(); |
| 55 |
|
|
//$this->_processState(); |
| 56 |
|
|
} |
| 57 |
|
|
|
| 58 |
|
|
// ------------------------------------------------------------------------------------------------ |
| 59 |
|
|
function setStatusAttribute($name, $value) { |
| 60 |
|
|
$this->state->set($name, $value); |
| 61 |
|
|
} |
| 62 |
|
|
function unsetStatusAttribute($name) { |
| 63 |
|
|
$this->state->unsetVar($name); |
| 64 |
|
|
} |
| 65 |
|
|
function getStatusAttribute($name) { |
| 66 |
|
|
return $this->state->get($name); |
| 67 |
|
|
} |
| 68 |
|
|
function clearStatusAttributes() { |
| 69 |
|
|
$this->state->clear(); |
| 70 |
|
|
} |
| 71 |
|
|
function dumpState() { |
| 72 |
|
|
$this->state->dump(); |
| 73 |
|
|
} |
| 74 |
|
|
function dumpState_get() { |
| 75 |
|
|
return $this->state->dump_get(); |
| 76 |
|
|
} |
| 77 |
|
|
|
| 78 |
|
|
|
| 79 |
|
|
// ------------------------------------------------------------------------------------ |
| 80 |
|
|
function getLink_ByArgs($link_args) { |
| 81 |
|
|
|
| 82 |
|
|
// data, which is displayed between "<a >"-"</a>-tags (parameters/args, which have a special meaning for building a html-link) |
| 83 |
|
|
// either converted via "htmlentities" (if "caption" is supplied) or directly set (if "innerHTML" is given) |
| 84 |
|
|
if (isset($link_args['caption'])) { $innerHTML = htmlentities($link_args['caption']); } |
| 85 |
|
|
if (isset($link_args['innerHTML'])) { $innerHTML = $link_args['innerHTML']; } |
| 86 |
|
|
|
| 87 |
|
|
// some html-attributes |
| 88 |
|
|
if ( isset($link_args['html_class']) ) { $html_attribs['class'] = $link_args['html_class']; } |
| 89 |
|
|
if ( isset($link_args['title']) ) { $html_attribs['title'] = ' ' . $link_args['title'] . ' '; } |
| 90 |
|
|
if ( isset($link_args['target']) ) { |
| 91 |
|
|
// get MetaItem where target-information (e.g. name of target frameset, wrapperpage, ...) is stored |
| 92 |
|
|
if ( $mi = $this->ic_navigationtargets->getMetaItem($link_args['target']) ) { |
| 93 |
|
|
// get name of targetframe from MetaItem |
| 94 |
|
|
if ($targetframe = $mi->getAttribute('targetframe')) { $html_attribs['target'] = $targetframe; } |
| 95 |
|
|
} |
| 96 |
|
|
} |
| 97 |
|
|
|
| 98 |
|
|
// "href" |
| 99 |
|
|
if (isset($link_args['href'])) { |
| 100 |
|
|
$html_attribs['href'] = $link_args['href']; |
| 101 |
|
|
} else { |
| 102 |
|
|
|
| 103 |
|
|
// filter "$link_args" through valid keys of output-args and return valid hash of output-args |
| 104 |
|
|
$outputargs = $this->state->getOutputArguments($link_args); |
| 105 |
|
|
|
| 106 |
|
|
// get complete url-parameters from outputargs |
| 107 |
|
|
$querystring = $this->httplib->getRequestString($outputargs); |
| 108 |
|
|
$html_attribs['href'] = '?' . $querystring; |
| 109 |
|
|
} |
| 110 |
|
|
|
| 111 |
|
|
if (isset($link_args['href_add'])) { |
| 112 |
|
|
$html_attribs['href'] .= '&' . $link_args['href_add']; |
| 113 |
|
|
} |
| 114 |
|
|
|
| 115 |
|
|
// build html-link |
| 116 |
|
|
$html_attribstring = getAttribStringFromHash($html_attribs, ' ', '=', '"'); |
| 117 |
|
|
// TODO: use "get_HtmlTag()" |
| 118 |
|
|
$link = "<a $html_attribstring>$innerHTML</a>"; |
| 119 |
|
|
|
| 120 |
|
|
// return built link |
| 121 |
|
|
return $link; |
| 122 |
|
|
|
| 123 |
|
|
} |
| 124 |
|
|
|
| 125 |
|
|
|
| 126 |
|
|
// ------------------------------------------------------------------------------------ |
| 127 |
|
|
function getLink_ByName($name) { |
| 128 |
|
|
// ($mi = $this->ic_menustructure->getMetaItem($name)) || trigger_error("could not get link \"$name\"", E_USER_ERROR); |
| 129 |
|
|
if ( $mi = $this->ic_menustructure->getMetaItem($name) ) { |
| 130 |
|
|
return $this->getLink_ByArgs($mi->getAttributes()); |
| 131 |
|
|
} |
| 132 |
|
|
} |
| 133 |
|
|
|
| 134 |
|
|
|
| 135 |
|
|
|
| 136 |
|
|
// -------------------------------------------------------------------------------------------------------------------------------- |
| 137 |
|
|
// generates output |
| 138 |
|
|
// -------------------------------------------------------------------------------------------------------------------------------- |
| 139 |
|
|
|
| 140 |
|
|
// ------------------------------------------------------------------------------------ |
| 141 |
|
|
function genArea_ErrorPage( $args ) { |
| 142 |
|
|
|
| 143 |
|
|
global $site; |
| 144 |
|
|
|
| 145 |
|
|
if ($mi_template_effective = $this->ic_pagetemplates->getMetaItem('error_404')) { |
| 146 |
|
|
$attribs = $mi_template_effective->getAttributes(); |
| 147 |
|
|
$file_error404 = $site->getAttribute('path_pages') . $attribs['file']; |
| 148 |
|
|
if (file_exists($file_error404)) { |
| 149 |
|
|
// TODO: pass "$args['reason']" to show on error-page |
| 150 |
|
|
$this->genArea( array('pseudopage' => 'error_404') ); |
| 151 |
|
|
} else { |
| 152 |
|
|
$die_dump_tracking = $this->dumpState_get(); |
| 153 |
|
|
$die_message = " |
| 154 |
|
|
{$args['reason']} <br> |
| 155 |
|
|
<br> |
| 156 |
|
|
While trying to open a proper page for bringing this error to you (\"error-404-template\"), another error occoured. <br> |
| 157 |
|
|
At most times this means that no physical file representing the \"error-404-template\" exists. <br> |
| 158 |
|
|
For your information: \"file_exists('$file_error404')\" returned \"false\". <br> |
| 159 |
|
|
<br> |
| 160 |
|
|
We also supply a variable-dump here, feel free sending a copy of it to us at <a href=\"mailto:x4@ilo.de\">x4@ilo.de</a>. <br> |
| 161 |
|
|
------------------------------------------------------------------------------------ <br> |
| 162 |
|
|
dump of arguments to \"\$tracking->genArea_ErrorPage()\": <br> |
| 163 |
|
|
(virtualpage=\"{$args['virtualpage']}\", pseudopage=\"{$args['pseudopage']}\") <br> |
| 164 |
|
|
------------------------------------------------------------------------------------ <br> |
| 165 |
|
|
dump of tracking: <br> |
| 166 |
|
|
$die_dump_tracking <br> |
| 167 |
|
|
------------------------------------------------------------------------------------ <br> |
| 168 |
|
|
"; |
| 169 |
|
|
die($die_message); |
| 170 |
|
|
} |
| 171 |
|
|
} |
| 172 |
|
|
|
| 173 |
|
|
} |
| 174 |
|
|
|
| 175 |
|
|
|
| 176 |
|
|
// ------------------------------------------------------------------------------------ |
| 177 |
|
|
function genArea($args) { |
| 178 |
|
|
|
| 179 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 180 |
|
|
// declaration/initialization/globalization of variables |
| 181 |
|
|
|
| 182 |
|
|
// important globals (these two objects are used *everywhere* to do (almost) *anything*) |
| 183 |
|
|
global $site; |
| 184 |
|
|
global $tracking; |
| 185 |
|
|
|
| 186 |
|
|
// some other variables which should be global but are not as important |
| 187 |
|
|
// for benchmarking |
| 188 |
|
|
global $benchmark_all; |
| 189 |
|
|
global $glbl_bool_benchmarking; |
| 190 |
|
|
|
| 191 |
|
|
// some variables used in page |
| 192 |
|
|
global $pageargs; |
| 193 |
|
|
global $areaargs; |
| 194 |
|
|
|
| 195 |
|
|
// some local ones |
| 196 |
|
|
|
| 197 |
|
|
// should the result of "genArea()" be returned instead of printed out? |
| 198 |
|
|
$bool_return = 0; |
| 199 |
|
|
|
| 200 |
|
|
|
| 201 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 202 |
|
|
// configuration ... |
| 203 |
|
|
|
| 204 |
|
|
// ... dependent on arguments to this function |
| 205 |
|
|
if (isset($args['returnContent'])) { $bool_return = 1; } |
| 206 |
|
|
|
| 207 |
|
|
$pageargs = array(); |
| 208 |
|
|
$areaargs = array(); |
| 209 |
|
|
|
| 210 |
|
|
|
| 211 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 212 |
|
|
// determination of proper virtualpage / pseudopage |
| 213 |
|
|
|
| 214 |
|
|
// init |
| 215 |
|
|
$virtualpage_name = ''; |
| 216 |
|
|
$pseudopage_name = ''; |
| 217 |
|
|
$genpage_name = ''; |
| 218 |
|
|
$pagetemplate_name = ''; |
| 219 |
|
|
|
| 220 |
|
|
// get name of virtual-page from tracking-state by default |
| 221 |
|
|
$virtualpage_name = $this->getStatusAttribute('virtualpage'); |
| 222 |
|
|
|
| 223 |
|
|
// modify virtual-page and set pseudo-page, if given |
| 224 |
|
|
isset($args['virtualpage']) && ($virtualpage_name = $args['virtualpage']); |
| 225 |
|
|
isset($args['pseudopage']) && ($pseudopage_name = $args['pseudopage']); |
| 226 |
|
|
|
| 227 |
|
|
// get virtual-page |
| 228 |
|
|
if ( $mi_VirtualPage = $this->ic_virtualpages->getMetaItem($virtualpage_name) ) { |
| 229 |
|
|
// remember reference to current virtual-page in "$tracking->ic_virtualpage_current" |
| 230 |
|
|
$this->ic_virtualpage_current = $mi_VirtualPage; |
| 231 |
|
|
} |
| 232 |
|
|
|
| 233 |
|
|
// is a pseudo-page given? |
| 234 |
|
|
if ($pseudopage_name) { |
| 235 |
|
|
$genpage_name = $pseudopage_name; |
| 236 |
|
|
} else { |
| 237 |
|
|
$genpage_name = $virtualpage_name; |
| 238 |
|
|
} |
| 239 |
|
|
|
| 240 |
|
|
|
| 241 |
|
|
|
| 242 |
|
|
$tmp_bool_ok = 0; |
| 243 |
|
|
// get virtual-page-MetaItem of gen-page |
| 244 |
|
|
if ( $mi_VirtualPage = $this->ic_virtualpages->getMetaItem($genpage_name) ) { |
| 245 |
|
|
|
| 246 |
|
|
// virtual-page-redirection |
| 247 |
|
|
// current: one level |
| 248 |
|
|
// TODO: n-levels |
| 249 |
|
|
if ($redir = $mi_VirtualPage->getAttribute('redirect')) { |
| 250 |
|
|
$genpage_name = $redir; |
| 251 |
|
|
$mi_VirtualPage = $this->ic_virtualpages->getMetaItem($genpage_name); |
| 252 |
|
|
} |
| 253 |
|
|
|
| 254 |
|
|
// determine page-template |
| 255 |
|
|
$pagetemplate_name = $mi_VirtualPage->getAttribute('pagetemplate'); |
| 256 |
|
|
if ($mi_PageTemplate = $this->ic_pagetemplates->getMetaItem($pagetemplate_name)) { |
| 257 |
|
|
$tmp_bool_ok = 1; |
| 258 |
|
|
} |
| 259 |
|
|
|
| 260 |
|
|
} |
| 261 |
|
|
|
| 262 |
|
|
|
| 263 |
|
|
|
| 264 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 265 |
|
|
// detect errors |
| 266 |
|
|
|
| 267 |
|
|
// if something's wrong with determining the virtual-page or the current page-template, |
| 268 |
|
|
// we deliver an error-page (current: 404 - file not found) via loading the "error_404" page-template. |
| 269 |
|
|
// we have to handle a special case here and test the physical file for existance before |
| 270 |
|
|
// calling "$this->genArea", because else we would get a recursive loop here and |
| 271 |
|
|
// soon (immediately) end up with a php-error: "PHP has encountered a Stack overflow" |
| 272 |
|
|
if (!$tmp_bool_ok) { |
| 273 |
|
|
$err_reason = "Something went wrong when determining template for effective page \"$genpage_name\" in \"\$tracking->genArea()\"."; |
| 274 |
|
|
$this->genArea_ErrorPage( array('reason' => $err_reason, 'virtualpage' => $virtualpage_name, 'pseudopage' => $pseudopage_name) ); |
| 275 |
|
|
|
| 276 |
|
|
//die("could not find requested virtual page *and* could not find entry for generating an error-page in \"ic_pagetemplates\""); |
| 277 |
|
|
exit; |
| 278 |
|
|
} |
| 279 |
|
|
|
| 280 |
|
|
|
| 281 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 282 |
|
|
// prepare page & template |
| 283 |
|
|
|
| 284 |
|
|
// get all attributes of current page-template |
| 285 |
|
|
$attribs = $mi_PageTemplate->getAttributes(); |
| 286 |
|
|
|
| 287 |
|
|
// physical file to be included |
| 288 |
|
|
$includefile = $site->getAttribute('path_pages') . $attribs['file']; |
| 289 |
|
|
|
| 290 |
|
|
// test physical file for existance |
| 291 |
|
|
// was: |
| 292 |
|
|
// if ( !file_exists($includefile) ) { trigger_error("could not include file \"$includefile\", quitting...", E_USER_ERROR); } |
| 293 |
|
|
// is: |
| 294 |
|
|
if ( !file_exists($includefile) ) { |
| 295 |
|
|
// was: |
| 296 |
|
|
// $this->genArea( array('pseudopage' => 'error_404') ); |
| 297 |
|
|
// exit; |
| 298 |
|
|
// is: |
| 299 |
|
|
$err_reason = "Could not find physical file \"$includefile\" when trying to open template \"$pagetemplate_name\" for effective page \"$genpage_name\" in \"\$tracking->genArea()\"."; |
| 300 |
|
|
$this->genArea_ErrorPage( array('reason' => $err_reason, 'virtualpage' => $virtualpage_name, 'pseudopage' => $pseudopage_name) ); |
| 301 |
|
|
exit; |
| 302 |
|
|
} |
| 303 |
|
|
|
| 304 |
|
|
|
| 305 |
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 306 |
|
|
// start rendering |
| 307 |
|
|
|
| 308 |
|
|
// ------------------------ |
| 309 |
|
|
// outputbuffering? |
| 310 |
|
|
if ($bool_return) { ob_start(); } |
| 311 |
|
|
|
| 312 |
|
|
// ------------------------ |
| 313 |
|
|
// header of main output |
| 314 |
|
|
|
| 315 |
|
|
// shall we render a body and stuff? |
| 316 |
|
|
if ( isset($attribs['bool_HTMLBody']) && ($attribs['bool_HTMLBody']) ) { |
| 317 |
|
|
// if we shall render a body, then here comes the "body-begin" |
| 318 |
|
|
$this->genArea( array('pseudopage' => 'static.content.begin') ); |
| 319 |
|
|
// write a html-form-start to output |
| 320 |
|
|
if ( isset($attribs['form']) ) { print "<form name=\"mf\">\n"; } |
| 321 |
|
|
} |
| 322 |
|
|
|
| 323 |
|
|
// ------------------------ |
| 324 |
|
|
// 1. virtual-page-job: set page-arguments |
| 325 |
|
|
if ($mi_VirtualPage) { |
| 326 |
|
|
// get page-arguments |
| 327 |
|
|
$pageargs = $mi_VirtualPage->getAttribute('pageargs'); |
| 328 |
|
|
$pageargs['virtualpage_effective'] = $mi_VirtualPage->getAttribute('name'); |
| 329 |
|
|
} |
| 330 |
|
|
|
| 331 |
|
|
// ------------------------ |
| 332 |
|
|
// 2. virtual-page-job: create all needed "ProcessObject"-objects for this page and call the requested handlers on them |
| 333 |
|
|
|
| 334 |
|
|
$bool_loadProcesses = 0; |
| 335 |
|
|
|
| 336 |
|
|
if (isset($this->ic_virtualpage_current)) { |
| 337 |
|
|
|
| 338 |
|
|
$vp_name = $this->ic_virtualpage_current->getAttribute('name'); |
| 339 |
|
|
$bool_forceHandlerExecution = $mi_VirtualPage->getAttribute('forceHandlerExecution'); |
| 340 |
|
|
|
| 341 |
|
|
if ($bool_forceHandlerExecution) { |
| 342 |
|
|
$bool_loadProcesses = 1; |
| 343 |
|
|
$handler_list = $mi_VirtualPage->getAttribute('handlers'); |
| 344 |
|
|
} else { |
| 345 |
|
|
$bool_loadProcesses = ($vp_name == $genpage_name); |
| 346 |
|
|
$handler_list = $this->ic_virtualpage_current->getAttribute('handlers'); |
| 347 |
|
|
} |
| 348 |
|
|
} |
| 349 |
|
|
|
| 350 |
|
|
if ($bool_loadProcesses) { |
| 351 |
|
|
|
| 352 |
|
|
if (count($handler_list)) { |
| 353 |
|
|
reset($handler_list); |
| 354 |
|
|
$this->loadModule('processes/objecthandlers.library'); |
| 355 |
|
|
while($handler = current($handler_list)) { |
| 356 |
|
|
$process =& $this->createProcess($handler['name_process']); |
| 357 |
|
|
$results_handler =& $process->callHandler($handler['name_handler'], $handler['results_requested'], $handler['args_optional']); |
| 358 |
|
|
|
| 359 |
|
|
/* |
| 360 |
|
|
// was: |
| 361 |
|
|
while(list($phpvar_name, $phpvar_value) = each($results_handler)) { |
| 362 |
|
|
//$$phpvar_name =& $results_handler[$phpvar_name]; |
| 363 |
|
|
} |
| 364 |
|
|
*/ |
| 365 |
|
|
|
| 366 |
|
|
// is: |
| 367 |
|
|
extract($results_handler); |
| 368 |
|
|
|
| 369 |
|
|
next($handler_list); |
| 370 |
|
|
} |
| 371 |
|
|
} |
| 372 |
|
|
|
| 373 |
|
|
} |
| 374 |
|
|
|
| 375 |
|
|
// ------------------------ |
| 376 |
|
|
// header of page |
| 377 |
|
|
if ( isset($attribs['bool_PageHeader']) && isset($pageargs['pageheader']) ) { print $pageargs['pageheader'] . "\n"; } |
| 378 |
|
|
|
| 379 |
|
|
// ------------------------ |
| 380 |
|
|
// misc |
| 381 |
|
|
if (isset($args['areaargs'])) { |
| 382 |
|
|
$areaargs = $args['areaargs']; |
| 383 |
|
|
} |
| 384 |
|
|
|
| 385 |
|
|
// ------------------------ |
| 386 |
|
|
// here comes the include |
| 387 |
|
|
$include_retval = include($includefile); |
| 388 |
|
|
|
| 389 |
|
|
// ------------------------ |
| 390 |
|
|
// footer of main output |
| 391 |
|
|
// shall we render a body and stuff? |
| 392 |
|
|
if ( isset($attribs['bool_HTMLBody']) && ($attribs['bool_HTMLBody']) ) { |
| 393 |
|
|
// close the form tag, if opened |
| 394 |
|
|
if ( isset($attribs['form']) ) { print "<input type=\"image\" width=\"0\" height=\"0\"></form>\n"; } |
| 395 |
|
|
// if we shall render a body, then here comes the "body-end" |
| 396 |
|
|
$this->genArea( array('pseudopage' => 'static.content.end') ); |
| 397 |
|
|
// dump our state |
| 398 |
|
|
//$this->dumpState(); |
| 399 |
|
|
} |
| 400 |
|
|
|
| 401 |
|
|
// ------------------------ |
| 402 |
|
|
// outputbuffering |
| 403 |
|
|
// is the outputput of this "genArea()"-run intended to be returned or printed? |
| 404 |
|
|
if ($bool_return) { |
| 405 |
|
|
$retval = ob_get_contents(); |
| 406 |
|
|
ob_end_clean(); |
| 407 |
|
|
return $retval; |
| 408 |
|
|
} |
| 409 |
|
|
|
| 410 |
|
|
} |
| 411 |
|
|
|
| 412 |
|
|
|
| 413 |
|
|
// =========================================================== |
| 414 |
|
|
// common methods |
| 415 |
|
|
|
| 416 |
|
|
// ------------------------------------------------------------------------------------ |
| 417 |
|
|
function loadLibrary($libname) { |
| 418 |
|
|
global $site; |
| 419 |
|
|
$site->loadLibrary($libname); |
| 420 |
|
|
} |
| 421 |
|
|
|
| 422 |
|
|
// ------------------------------------------------------------------------------------ |
| 423 |
|
|
function loadModule($modulename) { |
| 424 |
|
|
global $site; |
| 425 |
|
|
$site->loadModule($modulename); |
| 426 |
|
|
} |
| 427 |
|
|
|
| 428 |
|
|
// ------------------------------------------------------------------------------------ |
| 429 |
|
|
function redirect($args) { |
| 430 |
|
|
$this->httplib->redirect($args); |
| 431 |
|
|
} |
| 432 |
|
|
|
| 433 |
|
|
// ------------------------------------------------------------------------------------ |
| 434 |
|
|
function &createProcess($name) { |
| 435 |
|
|
return new $name($name); |
| 436 |
|
|
} |
| 437 |
|
|
|
| 438 |
|
|
|
| 439 |
|
|
// =========================================================== |
| 440 |
|
|
// user-methods |
| 441 |
|
|
|
| 442 |
|
|
// ------------------------------------------------------------------------------------ |
| 443 |
|
|
function authenticateUser($user, $pass) { |
| 444 |
|
|
$dq = new DataQuery(); |
| 445 |
|
|
$dq->setQuery("SELECT * FROM _dagl_users, wf_users_info WHERE _dagl_users._dagl_userid = wf_users_info._dagl_userid AND _dagl_users.authname='$user' AND _dagl_users.passwd='$pass';"); |
| 446 |
|
|
$dq->query(); |
| 447 |
|
|
if ($dq->getRowCount()) { |
| 448 |
|
|
$dq->next(); |
| 449 |
|
|
$entry = $dq->getResult(); |
| 450 |
|
|
$this->setStatusAttribute('login::userid', $entry['user_id']); |
| 451 |
|
|
return 1; |
| 452 |
|
|
} |
| 453 |
|
|
} |
| 454 |
|
|
|
| 455 |
|
|
// ------------------------------------------------------------------------------------ |
| 456 |
|
|
function updateDaglUser($userid, $user, $pass) { |
| 457 |
|
|
$dq = new DataQuery(); |
| 458 |
|
|
$dq->setQuery("UPDATE _dagl_users SET authname='$user', passwd='$pass' WHERE _dagl_userid=$userid;"); |
| 459 |
|
|
$dq->query(); |
| 460 |
|
|
} |
| 461 |
|
|
|
| 462 |
|
|
// ------------------------------------------------------------------------------------ |
| 463 |
|
|
function existsDaglUser($userid) { |
| 464 |
|
|
$dq = new DataQuery(); |
| 465 |
|
|
$dq->setQuery("SELECT _dagl_userid FROM _dagl_users WHERE _dagl_userid=$userid;"); |
| 466 |
|
|
$dq->query(); |
| 467 |
|
|
return $dq->getRowCount(); |
| 468 |
|
|
} |
| 469 |
|
|
|
| 470 |
|
|
// ------------------------------------------------------------------------------------ |
| 471 |
|
|
function createDaglUser() { |
| 472 |
|
|
|
| 473 |
|
|
$user = getUniqueId(); |
| 474 |
|
|
$pass = getUniqueId(); |
| 475 |
|
|
|
| 476 |
|
|
$dq = new DataQuery(); |
| 477 |
|
|
$dq->setQuery("INSERT INTO _dagl_users (_dagl_userid, authname, passwd) VALUES (null, '$user', '$pass');"); |
| 478 |
|
|
$dq->query(); |
| 479 |
|
|
$userid = $dq->lastInsertId; |
| 480 |
|
|
return $userid; |
| 481 |
|
|
} |
| 482 |
|
|
|
| 483 |
|
|
// ------------------------------------------------------------------------------------ |
| 484 |
|
|
function setUserState($userid, $context, $varname, $value) { |
| 485 |
|
|
|
| 486 |
|
|
//$value_serialized = serialize($value); |
| 487 |
|
|
$value_serialized = addslashes(serialize($value)); |
| 488 |
|
|
|
| 489 |
|
|
$dq = new DataQuery(); |
| 490 |
|
|
|
| 491 |
|
|
$criteria = "_dagl_userid=$userid AND context='$context' AND varname='$varname'"; |
| 492 |
|
|
|
| 493 |
|
|
$sql = "SELECT * FROM _dagl_users_state WHERE $criteria;"; |
| 494 |
|
|
$dq->setQuery($sql); |
| 495 |
|
|
$dq->query(); |
| 496 |
|
|
if ($dq->getRowCount()) { |
| 497 |
|
|
$sql = "UPDATE _dagl_users_state SET value='$value_serialized' WHERE $criteria"; |
| 498 |
|
|
} else { |
| 499 |
|
|
$sql = "INSERT INTO _dagl_users_state (_dagl_userid, context, varname, value) VALUES ('$userid', '$context', '$varname', '$value_serialized');"; |
| 500 |
|
|
} |
| 501 |
|
|
$dq->setQuery($sql); |
| 502 |
|
|
$dq->query(); |
| 503 |
|
|
|
| 504 |
|
|
} |
| 505 |
|
|
|
| 506 |
|
|
// ------------------------------------------------------------------------------------ |
| 507 |
|
|
function getUserState($userid, $context, $varname) { |
| 508 |
|
|
$criteria = "_dagl_userid=$userid AND context='$context' AND varname='$varname'"; |
| 509 |
|
|
$sql = "SELECT * FROM _dagl_users_state WHERE $criteria;"; |
| 510 |
|
|
$dq = new DataQuery(); |
| 511 |
|
|
$dq->setQuery($sql); |
| 512 |
|
|
$dq->query(); |
| 513 |
|
|
if ($dq->getRowCount()) { |
| 514 |
|
|
$dq->next(); |
| 515 |
|
|
$stateentry = $dq->getResult(); |
| 516 |
|
|
$value_serialized = $stateentry['value']; |
| 517 |
|
|
$value_unserialized = unserialize($value_serialized); |
| 518 |
|
|
return $value_unserialized; |
| 519 |
|
|
} |
| 520 |
|
|
} |
| 521 |
|
|
|
| 522 |
|
|
// ------------------------------------------------------------------------------------ |
| 523 |
|
|
function unsetUserState($userid, $context, $varname) { |
| 524 |
|
|
$criteria = "_dagl_userid=$userid AND context='$context' AND varname='$varname'"; |
| 525 |
|
|
$sql = "DELETE FROM _dagl_users_state WHERE $criteria;"; |
| 526 |
|
|
$dq = new DataQuery(); |
| 527 |
|
|
$dq->setQuery($sql); |
| 528 |
|
|
$dq->query(); |
| 529 |
|
|
} |
| 530 |
|
|
|
| 531 |
|
|
} |
| 532 |
|
|
?> |