Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gettext: translation partial "override" or "cascade" possible? 1

Status
Not open for further replies.

OsakaWebbie

Programmer
Feb 11, 2003
628
JP
I have a bilingual application that has one main spot for the code (which is continually being developed) but several clients on virtual hosts. For ease of maintenance I want to keep a single main locale directory (so that when I add new strings I only have to update one place). But I also want the ability to customize a few strings here and there for some clients. My brain recalls things like "core overrides" in Joomla templates and the cascading nature of CSS, and I'm wondering if I can do something similar with translation files - to have a file with a small subset of strings in the client directory when needed, and have PHP use the client-specific string when it is present but otherwise just the one in the "global" file for that language. I did some googling but didn't find anything like that. Thoughts?
 
should not be too hard. just create a dummy language for your pot file (for the bespoke strings) and use a wrapper function like the wp _().

in the function first test for a match on the dummy language and if nothing exists for that (the result is empty), call getttext (or whatever language system you wish) on the default language for that user).

 
Thanks. Pardon my ignorance, but can you explain more about how to implement a "wrapper function"? I'm already calling _() throughout my code for all displayed strings (I learned it in some i18n tutorial somewhere - I have no idea where it is declared or how it works). I can't redeclare _(), so would I have to do a global change to some other function name? My code is very old-school procedural in style - I haven't gotten my brain around OOP yet (yeah, I know, I need to acknowledge the existence of the 21st century!).
 
oops. i had intended to type a double underscore. or perhaps i did and the parser overrode it?

the single underscore is simply a built in alias for gettext();

Code:
[i][COLOR=#9A1900 ]/* may need also to set env vars */[/color][/i]
[b][COLOR=#000000 ]bindtextdomain[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'normalDomain'[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'/path/to/normal/text/domain'[/color][COLOR=#990000 ]);[/color]
[b][COLOR=#000000 ]bindtextdomain[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'specialDomain'[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'/path/to/special/text/domain'[/color][COLOR=#990000 ]);[/color]
[b][COLOR=#000000 ]textdomain[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'normalDomain'[/color][COLOR=#990000 ]);[/color]

Code:
[b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]__[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$string[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
  [COLOR=#009900 ]$o[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]dcgettext[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$string[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'specialDomain'[/color][COLOR=#990000 ],[/color] [COLOR=#993399 ]6[/color][COLOR=#990000 ])[/color] [COLOR=#990000 ];[/color]  [i][COLOR=#9A1900 ]//look up string in special domain[/color][/i]
  [b][COLOR=#0000FF ]return[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$o[/color] [COLOR=#990000 ]==[/color] [COLOR=#009900 ]$string[/color][COLOR=#990000 ])[/color] [COLOR=#990000 ]?[/color] [b][COLOR=#000000 ]gettext[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$string[/color][COLOR=#990000 ])[/color] [COLOR=#990000 ]:[/color] [COLOR=#009900 ]$o[/color][COLOR=#990000 ];[/color]
[COLOR=#FF0000 ]}[/color]

on OOP, I'm not a slave to using OOP for every app. a one off, quick never to be looked at again app can be written in the grubbiest manner you like so long as it works. there is no point in spending time optimising code to run 20% faster or neater if it will only run once and take an hour in total.

but if you are building entity based database driven sites (i.e. if you can break down your application in to a series of logical entities that store data about themselves) then OOP makes a lot of sense. Each entity mapping your database tables (usually).

For example, a user table that is also used for authentication may look something like this

Code:
[b][COLOR=#0000FF ]class[/color][/b] user [b][COLOR=#0000FF ]extends[/color][/b] base [COLOR=#FF0000 ]{[/color]
 public [COLOR=#009900 ]$table[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]'userTable'[/color][COLOR=#990000 ];[/color]
 public [COLOR=#009900 ]$primary[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]'userID'[/color][COLOR=#990000 ];[/color]
 public [COLOR=#009900 ]$fields[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'userID'[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'userName'[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'userPassword'[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'userEmail'[/color][COLOR=#990000 ]);[/color]

 public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]__construct[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color] parent[COLOR=#990000 ]::[/color][b][COLOR=#000000 ]__construct[/color][/b][COLOR=#990000 ]();[/color] [COLOR=#FF0000 ]}[/color]
[COLOR=#FF0000 ]}[/color]

Code:
[b][COLOR=#0000FF ]class[/color][/b] currentUser [b][COLOR=#0000FF ]extends[/color][/b] user [COLOR=#FF0000 ]{[/color]
 public [COLOR=#009900 ]$isLoggedIn[/color] [COLOR=#990000 ]=[/color] false[COLOR=#990000 ];[/color]
 public [COLOR=#009900 ]$isAdmin[/color] [COLOR=#990000 ]=[/color] false[COLOR=#990000 ];[/color]

 public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]__construct[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]parent[COLOR=#990000 ]::[/color][b][COLOR=#000000 ]__construct[/color][/b][COLOR=#990000 ]();[/color] [COLOR=#FF0000 ]}[/color]
 
 public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]isLoggedIn[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][i][COLOR=#9A1900 ]//check to see whether user is logged in or whether this is a log in request[/color][/i]
 [COLOR=#FF0000 ]}[/color]

 public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]isAdmin[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
   [b][COLOR=#0000FF ]return[/color][/b] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]isAdmin[COLOR=#990000 ];[/color]
 [COLOR=#FF0000 ]}[/color]

[COLOR=#FF0000 ]}[/color]

and the base class from of these too are inheritors is an abstraction layer that I use which looks like this

Code:
[COLOR=#990000 ]<?php[/color]

[i][COLOR=#9A1900 ]/**[/color][/i]
[i][COLOR=#9A1900 ] * database manipulation class. [/color][/i]
[i][COLOR=#9A1900 ] * assumes that the RDBMS is mysql.  It will not work with sqlite because of the insert method using the SET syntax.[/color][/i]
[i][COLOR=#9A1900 ] * this could be rewritten to be more cross db friendly.[/color][/i]
[i][COLOR=#9A1900 ] */[/color][/i]
[b][COLOR=#0000FF ]class[/color][/b] base [COLOR=#FF0000 ]{[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]__construct[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]foreach[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]fields [b][COLOR=#0000FF ]as[/color][/b] [COLOR=#009900 ]$field[/color][COLOR=#990000 ]):[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ](![/color][b][COLOR=#0000FF ]isset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$field[/color][COLOR=#FF0000 ]}[/color][COLOR=#990000 ]))[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$field[/color][COLOR=#FF0000 ]}[/color] [COLOR=#990000 ]=[/color] NULL[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]endforeach[/color][/b][COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]getPrimary[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#990000 ]![/color][b][COLOR=#0000FF ]empty[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]primary[COLOR=#FF0000 ]}[/color][COLOR=#990000 ])[/color] [COLOR=#990000 ]?[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]primary[COLOR=#FF0000 ]}[/color] [COLOR=#990000 ]:[/color] false[COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]save[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]getPrimary[/color][/b][COLOR=#990000 ]()[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ]):[/color]
[tab][tab][tab]
[tab][tab][tab][COLOR=#009900 ]$return[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]insert[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#0000FF ]else[/color][/b][COLOR=#990000 ]:[/color]
[tab][tab][tab][COLOR=#009900 ]$return[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]update[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#009900 ]$return[/color][COLOR=#990000 ];[/color]
[tab][tab]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]insert[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]global[/color][/b] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$params[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][COLOR=#009900 ]$sql[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"INSERT into {$this->table} SET "[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]foreach[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]fields [b][COLOR=#0000FF ]as[/color][/b] [COLOR=#009900 ]$key[/color][COLOR=#990000 ]=>[/color][COLOR=#009900 ]$field[/color][COLOR=#990000 ]):[/color]
[tab][tab][tab][COLOR=#009900 ]$fields[/color][COLOR=#990000 ][][/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"`$field` = :{$field}"[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][COLOR=#009900 ]$params[/color][COLOR=#990000 ][[/color][COLOR=#009900 ]$field[/color][COLOR=#990000 ]][/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]is_array[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$field[/color][COLOR=#FF0000 ]}[/color][COLOR=#990000 ])[/color] [COLOR=#990000 ]?[/color] [b][COLOR=#000000 ]serialize[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$field[/color][COLOR=#FF0000 ]}[/color][COLOR=#990000 ])[/color] [COLOR=#990000 ]:[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$field[/color][COLOR=#FF0000 ]}[/color][COLOR=#990000 ];[/color] 
[tab][tab][b][COLOR=#0000FF ]endforeach[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$query[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$sql[/color] [COLOR=#990000 ].[/color] [b][COLOR=#000000 ]implode[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]','[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$fields[/color][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]prepare[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$query[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$pdo[/color][COLOR=#990000 ],[/color] [b][COLOR=#0000FF ]__LINE__[/color][/b][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$r[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]execute[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$params[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$r[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color][COLOR=#990000 ],[/color] [b][COLOR=#0000FF ]__LINE__[/color][/b][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]primary[COLOR=#FF0000 ]}[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]lastInsertID[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]rowCount[/color][/b][COLOR=#990000 ]();[/color] 
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]update[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]global[/color][/b] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$params[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][COLOR=#009900 ]$sql[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"UPDATE {$this->table} SET "[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]foreach[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]fields [b][COLOR=#0000FF ]as[/color][/b] [COLOR=#009900 ]$key[/color][COLOR=#990000 ]=>[/color][COLOR=#009900 ]$field[/color][COLOR=#990000 ]):[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$field[/color] [COLOR=#990000 ]===[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]primary[COLOR=#990000 ])[/color] [b][COLOR=#0000FF ]continue[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][tab][COLOR=#009900 ]$fields[/color][COLOR=#990000 ][][/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"`$field` = :{$field}"[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][COLOR=#009900 ]$params[/color][COLOR=#990000 ][[/color][COLOR=#009900 ]$field[/color][COLOR=#990000 ]][/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]is_array[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$field[/color][COLOR=#FF0000 ]}[/color][COLOR=#990000 ])[/color] [COLOR=#990000 ]?[/color] [b][COLOR=#000000 ]serialize[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$field[/color][COLOR=#FF0000 ]}[/color][COLOR=#990000 ])[/color] [COLOR=#990000 ]:[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$field[/color][COLOR=#FF0000 ]}[/color][COLOR=#990000 ];[/color] 
[tab][tab][b][COLOR=#0000FF ]endforeach[/color][/b][COLOR=#990000 ];[/color]
[tab][tab]
[tab][tab][COLOR=#009900 ]$query[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$sql[/color] [COLOR=#990000 ].[/color] [b][COLOR=#000000 ]implode[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]','[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$fields[/color][COLOR=#990000 ])[/color] [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]" WHERE {$this->primary} = :{$this->primary}"[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$params[/color][COLOR=#990000 ][[/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]primary[COLOR=#990000 ]][/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]getPrimary[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]prepare[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$query[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$pdo[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]errorInfo[/color][/b][COLOR=#990000 ]());[/color]
[tab][tab][COLOR=#009900 ]$r[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]execute[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$params[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$r[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]errorInfo[/color][/b][COLOR=#990000 ]());[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]rowCount[/color][/b][COLOR=#990000 ]();[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]delete[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]global[/color][/b] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$sql[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"delete from {$this->table} where {$this->primary} = ?"[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$params[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]getPrimary[/color][/b][COLOR=#990000 ]());[/color]
[tab][tab][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]prepare[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$sql[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$pdo[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]errorInfo[/color][/b][COLOR=#990000 ]());[/color]
[tab][tab][COLOR=#009900 ]$r[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]execute[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$params[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$r[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]errorInfo[/color][/b][COLOR=#990000 ]());[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]rowCount[/color][/b][COLOR=#990000 ]();[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]loadFromID[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$id[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]global[/color][/b] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$sql[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"Select * from {$this->table} where {$this->primary} = ?"[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]prepare[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$sql[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$pdo[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]errorInfo[/color][/b][COLOR=#990000 ]());[/color]
[tab][tab][COLOR=#009900 ]$r[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]execute[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$id[/color][COLOR=#990000 ]));;[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$r[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]errorInfo[/color][/b][COLOR=#990000 ]());[/color]
[tab][tab][COLOR=#009900 ]$row[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]fetchObject[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]load[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$row[/color][COLOR=#990000 ]);[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]load[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$row[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#000000 ]is_array[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$row[/color][COLOR=#990000 ]))[/color] [COLOR=#009900 ]$row[/color] [COLOR=#990000 ]=[/color] [COLOR=#990000 ]([/color]object[COLOR=#990000 ])[/color] [COLOR=#009900 ]$row[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]foreach[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]fields [b][COLOR=#0000FF ]as[/color][/b] [COLOR=#009900 ]$field[/color][COLOR=#990000 ]):[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#0000FF ]isset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$row[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$field[/color][COLOR=#FF0000 ]}[/color][COLOR=#990000 ]))[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$field[/color][COLOR=#FF0000 ]}[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$row[/color][COLOR=#990000 ]->[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$field[/color][COLOR=#FF0000 ]}[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]endforeach[/color][/b][COLOR=#990000 ];[/color] 
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]bail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$array[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$line[/color] [COLOR=#990000 ]=[/color] null[COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]echo[/color][/b] [COLOR=#FF0000 ]'<pre>'[/color] [COLOR=#990000 ].[/color] [b][COLOR=#000000 ]print_r[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$array[/color][COLOR=#990000 ],[/color] true[COLOR=#990000 ])[/color] [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'</pre>'[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]echo[/color][/b] [COLOR=#FF0000 ]'<pre> '[/color] [COLOR=#990000 ].[/color] [b][COLOR=#000000 ]print_r[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$array[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]errorInfo[/color][/b][COLOR=#990000 ](),[/color] true[COLOR=#990000 ])[/color] [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'</pre>'[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$line[/color][COLOR=#990000 ])[/color]  [b][COLOR=#0000FF ]echo[/color][/b] [COLOR=#FF0000 ]'<pre>On Line '[/color] [COLOR=#990000 ].[/color] [COLOR=#009900 ]$line[/color][COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'</pre>'[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]echo[/color][/b] [COLOR=#FF0000 ]'<pre>'[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#000000 ]debug_print_backtrace[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#0000FF ]echo[/color][/b] [COLOR=#FF0000 ]'</pre>'[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]die[/color][/b][COLOR=#990000 ];[/color][tab]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]isUnique[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$field[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]global[/color][/b] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$query[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"Select count(*) as c from {$this->table} where `$field` = ?"[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]prepare[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$query[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$pdo[/color][COLOR=#990000 ],[/color] [b][COLOR=#0000FF ]__LINE__[/color][/b][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$result[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]execute[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][COLOR=#009900 ]$field[/color][COLOR=#990000 ]));[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$result[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color][COLOR=#990000 ],[/color] [b][COLOR=#0000FF ]__LINE__[/color][/b][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$row[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]fetchObject[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ](([/color]string[COLOR=#990000 ])[/color] [COLOR=#009900 ]$row[/color][COLOR=#990000 ]->[/color]c [COLOR=#990000 ]==[/color] [COLOR=#FF0000 ]"0"[/color][COLOR=#990000 ])[/color] [b][COLOR=#0000FF ]return[/color][/b] true[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] false[COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]
[COLOR=#FF0000 ]}[/color]
[COLOR=#990000 ]?>[/color]

so [b][COLOR=#0000FF ]for[/color][/b] example [b][COLOR=#0000FF ]if[/color][/b] you were setting up a [b][COLOR=#0000FF ]new[/color][/b] user [b][COLOR=#0000FF ]and[/color][/b] the details were all in the post superglobal you would [b][COLOR=#0000FF ]do[/color][/b] this

[COLOR=#990000 ][[/color]code[COLOR=#990000 ]][/color]
[COLOR=#009900 ]$user[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] user[COLOR=#990000 ];[/color]
[COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]load[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ]);[/color]
[COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]save[/color][/b][COLOR=#990000 ]();[/color]

and to delete a user with id of 7

Code:
[COLOR=#009900 ]$user[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] user[COLOR=#990000 ];[/color]
[COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]loadFromID[/color][/b][COLOR=#990000 ]([/color][COLOR=#993399 ]7[/color][COLOR=#990000 ]);[/color]
[COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]delete[/color][/b][COLOR=#990000 ]();[/color]

to update a user from a form that has the ID as a hidden field
Code:
[COLOR=#009900 ]$user[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] user[COLOR=#990000 ];[/color]
[COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]loadFromID[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color]primary[COLOR=#990000 ]]);[/color]
[COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]load[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ]);[/color]
[COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]save[/color][/b][COLOR=#990000 ]();[/color]

and to see whether a user is authorised

Code:
[COLOR=#009900 ]$cU[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] [b][COLOR=#000000 ]currentUser[/color][/b][COLOR=#990000 ]();[/color]
[b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$cU[/color] [COLOR=#990000 ]->[/color] [b][COLOR=#000000 ]isLoggedIn[/color][/b][COLOR=#990000 ]()[/color] [COLOR=#990000 ])[/color] [COLOR=#990000 ]:[/color]
 [i][COLOR=#9A1900 ]//ok[/color][/i]
[b][COLOR=#0000FF ]else[/color][/b][COLOR=#990000 ]:[/color]
 [i][COLOR=#9A1900 ]//kick to denied[/color][/i]
[b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]

because base.php is completely agnostic of any particular application it can be reused without any changes (more or less). and if you set up your objects like this the it makes for very rapid deployment and a relatively secure code base (I also include a validate() function in my inherited classes that is called by save to ensure data integrity).

it was when I got to grips with inheritance and the advantages it offered for this set up that I started developing in OOP. There is still plenty of procedural code in my apps, but it tends to be part of the presentation layer (controlling foreach loops for html display etc), rather than part of the core logic.

in case it is not obvious, my apps are all controlled by a dispatch mechanism. so all interaction is between the user and a single page (index.php), that then tests variables and decides what to do. This is what my index.php looks like

Code:
[COLOR=#990000 ]<?php[/color]
[b][COLOR=#000080 ]require_once[/color][/b] [COLOR=#FF0000 ]'config.php'[/color][COLOR=#990000 ];[/color]
[COLOR=#009900 ]$despatcher[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] despatcher[COLOR=#990000 ];[/color]
[COLOR=#009900 ]$despatcher[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]despatch[/color][/b][COLOR=#990000 ]();[/color]
[COLOR=#990000 ]?>[/color]

and this is an excerpt from a recent despatcher (note that the merging of POST and GET in the way that I do below is not a great idea for production sites. this was for development only so I could 'run' forms from the address bar

Code:
[COLOR=#990000 ]<?php[/color]
[COLOR=#009900 ]$req[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]();[/color]
[b][COLOR=#0000FF ]class[/color][/b] despatcher [COLOR=#FF0000 ]{[/color]
[tab]
[tab]public [COLOR=#009900 ]$action[/color][COLOR=#990000 ];[/color]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]__construct[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]global[/color][/b] [COLOR=#009900 ]$req[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$req[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]array_merge[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_GET[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$_POST[/color][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]action [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]isset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$req[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'jAction'[/color][COLOR=#990000 ]])[/color] [COLOR=#990000 ]?[/color] [b][COLOR=#000000 ]str_replace[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]' '[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]''[/color][COLOR=#990000 ],[/color] [b][COLOR=#000000 ]strtolower[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#000000 ]trim[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$req[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'jAction'[/color][COLOR=#990000 ]])))[/color] [COLOR=#990000 ]:[/color] [COLOR=#FF0000 ]''[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]isAjax [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]isset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$req[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'isAjax'[/color][COLOR=#990000 ]]);[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]despatch[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]global[/color][/b] [COLOR=#009900 ]$req[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$currentUser[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$message[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]switch[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]action[COLOR=#990000 ]):[/color]
[tab][tab]

[tab][tab][i][COLOR=#9A1900 ]/************** USER CASES ******************/[/color][/i]
[tab][tab]
[tab][tab][b][COLOR=#0000FF ]case[/color][/b] [COLOR=#FF0000 ]'adduser'[/color][COLOR=#990000 ]:[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ](![/color][b][COLOR=#000000 ]isAdmin[/color][/b][COLOR=#990000 ]())[/color] [b][COLOR=#000000 ]doUnauthorised[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][COLOR=#009900 ]$user[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] user[COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#000080 ]require_once[/color][/b] TEMPLATE [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'user/edit.php'[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]break[/color][/b][COLOR=#990000 ];[/color]
[tab][tab]
[tab][tab][b][COLOR=#0000FF ]case[/color][/b] [COLOR=#FF0000 ]'deleteuser'[/color][COLOR=#990000 ]:[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ](![/color][b][COLOR=#000000 ]isAdmin[/color][/b][COLOR=#990000 ]())[/color] [b][COLOR=#000000 ]doUnauthorised[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][COLOR=#009900 ]$user[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] user[COLOR=#990000 ];[/color]
[tab][tab][tab][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]loadFromID[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$req[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'userID'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]getPrimary[/color][/b][COLOR=#990000 ]()[/color] [COLOR=#990000 ]>[/color] [COLOR=#993399 ]0[/color] [COLOR=#990000 ]):[/color]
[tab][tab][tab][tab][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]delete[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#000080 ]include[/color][/b] TEMPLATE [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'user/list.php'[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]break[/color][/b][COLOR=#990000 ];[/color]
[tab][tab]
[tab][tab][b][COLOR=#0000FF ]case[/color][/b] [COLOR=#FF0000 ]'edituser'[/color][COLOR=#990000 ]:[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ](![/color][b][COLOR=#000000 ]isAdmin[/color][/b][COLOR=#990000 ]())[/color] [b][COLOR=#000000 ]doUnauthorised[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][COLOR=#009900 ]$user[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] user[COLOR=#990000 ];[/color]
[tab][tab][tab][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]loadFromID[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$req[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'userID'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]getPrimary[/color][/b][COLOR=#990000 ]()[/color] [COLOR=#990000 ]>[/color] [COLOR=#993399 ]0[/color] [COLOR=#990000 ]):[/color]
[tab][tab][tab][tab][b][COLOR=#000080 ]include[/color][/b] TEMPLATE [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'user/edit.php'[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#0000FF ]else[/color][/b][COLOR=#990000 ]:[/color]
[tab][tab][tab][tab][b][COLOR=#000080 ]include[/color][/b] TEMPLATE [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'user/list.php'[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]

[tab][tab][b][COLOR=#0000FF ]break[/color][/b][COLOR=#990000 ];[/color]
[tab][tab]
[tab][tab][b][COLOR=#0000FF ]case[/color][/b] [COLOR=#FF0000 ]'saveuser'[/color][COLOR=#990000 ]:[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ](![/color][COLOR=#009900 ]$currentUser[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]can[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$req[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'userAuthorisationLevel'[/color][COLOR=#990000 ]]))[/color] [b][COLOR=#000000 ]doUnauthorised[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][COLOR=#009900 ]$user[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] user[COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ](![/color][b][COLOR=#0000FF ]empty[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$req[/color][COLOR=#990000 ][[/color][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color]primary[COLOR=#990000 ]])):[/color]
[tab][tab][tab][tab][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]loadFromID[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$req[/color][COLOR=#990000 ][[/color][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color]primary[COLOR=#990000 ]]);[/color]
[tab][tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][tab][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]load[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$req[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#000000 ]strlen[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]getPrimary[/color][/b][COLOR=#990000 ]())[/color]  [COLOR=#990000 ]==[/color] [COLOR=#993399 ]0[/color][COLOR=#990000 ]):[/color]
[tab][tab][tab][tab][COLOR=#009900 ]$result[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]register[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$result[/color][COLOR=#990000 ]):[/color]
[tab][tab][tab][tab][tab][COLOR=#009900 ]$message[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"The new user has been registered and an email dispatched"[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]else[/color][/b][COLOR=#990000 ]:[/color]
[tab][tab][tab][tab][tab][COLOR=#009900 ]$message[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"This user could not be registered"[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#0000FF ]else[/color][/b][COLOR=#990000 ]:[/color]
[tab][tab][tab][tab][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]save[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][tab][COLOR=#009900 ]$message[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"The amended user details have been saved"[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#000080 ]include[/color][/b] TEMPLATE [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'user/list.php'[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]break[/color][/b][COLOR=#990000 ];[/color]
[tab][tab]
[tab][tab][b][COLOR=#0000FF ]case[/color][/b] [COLOR=#FF0000 ]'newpassword'[/color][COLOR=#990000 ]:[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ](![/color][b][COLOR=#000000 ]isAdmin[/color][/b][COLOR=#990000 ]())[/color] [b][COLOR=#000000 ]doUnauthorised[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][COLOR=#009900 ]$user[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] user[COLOR=#990000 ];[/color]
[tab][tab][tab][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]loadFromID[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$req[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'userID'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][tab][COLOR=#009900 ]$user[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]regeneratePassword[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][COLOR=#009900 ]$message[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"A new password has been generated and sent to the user's registered email address"[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#000080 ]include[/color][/b] TEMPLATE [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'user/list.php'[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]break[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][tab]
[tab][tab][b][COLOR=#0000FF ]case[/color][/b] [COLOR=#FF0000 ]'userlist'[/color][COLOR=#990000 ]:[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ](![/color][b][COLOR=#000000 ]isAdmin[/color][/b][COLOR=#990000 ]())[/color] [b][COLOR=#000000 ]doUnauthorised[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][COLOR=#009900 ]$users[/color] [COLOR=#990000 ]=[/color] factory[COLOR=#990000 ]::[/color][b][COLOR=#000000 ]getAll[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'user'[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][b][COLOR=#000080 ]require[/color][/b] TEMPLATE [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'user/list.php'[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]break[/color][/b][COLOR=#990000 ];[/color]
[tab][tab]
[tab][tab][b][COLOR=#0000FF ]case[/color][/b] [COLOR=#FF0000 ]'logout'[/color][COLOR=#990000 ]:[/color]
[tab][tab][tab][COLOR=#009900 ]$currentUser[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]logout[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#0000FF ]break[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][i][COLOR=#9A1900 ]/************** END USER CASES ******************/[/color][/i]
[tab]
[tab][tab][b][COLOR=#0000FF ]default[/color][/b][COLOR=#990000 ]:[/color]
[tab][tab][tab][b][COLOR=#000080 ]include[/color][/b] TEMPLATE [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'frontpage.php'[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]endswitch[/color][/b][COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]
[COLOR=#FF0000 ]}[/color]
 
and for what it's worth, here is the actual user.php and currentUser.php that I used in the above dev app

Code:
[COLOR=#990000 ]<?php[/color]

[b][COLOR=#0000FF ]class[/color][/b] user [b][COLOR=#0000FF ]extends[/color][/b] base [COLOR=#FF0000 ]{[/color]
[tab]
[tab]public [COLOR=#009900 ]$userAuthorisationLevel[/color] [COLOR=#990000 ]=[/color] [COLOR=#993399 ]0[/color][COLOR=#990000 ];[/color]
[tab]public [COLOR=#009900 ]$table[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]'users'[/color][COLOR=#990000 ];[/color]
[tab]public [COLOR=#009900 ]$primary[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]'userID'[/color][COLOR=#990000 ];[/color]
[tab]public [COLOR=#009900 ]$fields[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color] [COLOR=#FF0000 ]'userID'[/color][COLOR=#990000 ],[/color][COLOR=#FF0000 ]'userEmail'[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'userFirstName'[/color][COLOR=#990000 ],[/color][COLOR=#FF0000 ]'userSurname'[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'userPassword'[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'userAuthorisationLevel'[/color] [COLOR=#990000 ]);[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]__construct[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab]parent[COLOR=#990000 ]::[/color][b][COLOR=#000000 ]__construct[/color][/b][COLOR=#990000 ]();[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]saveNew[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] parent[COLOR=#990000 ]::[/color][b][COLOR=#000000 ]saveNew[/color][/b][COLOR=#990000 ]();[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]crypt[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$string[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] [b][COLOR=#000000 ]sha1[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$string[/color][COLOR=#990000 ]);[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]loadFromEmail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$email[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]global[/color][/b] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$query[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"Select * from {$this->table} where userEmail = ?"[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]prepare[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$query[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$pdo[/color][COLOR=#990000 ],[/color] [b][COLOR=#0000FF ]__LINE__[/color][/b][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$result[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]execute[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$email[/color][COLOR=#990000 ]));[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$result[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color][COLOR=#990000 ],[/color] [b][COLOR=#0000FF ]__LINE__[/color][/b][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$row[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]fetchObject[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]load[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$row[/color][COLOR=#990000 ]);[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]isAdmin[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]userAuthorisationLevel [COLOR=#990000 ]>=[/color] [COLOR=#993399 ]8[/color] [COLOR=#990000 ]);[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]isSuperUser[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]userAuthorisationLevel [COLOR=#990000 ]==[/color] [COLOR=#993399 ]8[/color] [COLOR=#990000 ]);[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]register[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]key [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]generateRandomAlphaNumericString[/color][/b][COLOR=#990000 ]([/color][COLOR=#993399 ]6[/color][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]userPassword [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]crypt[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]key[COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ](![/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]isUnique[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'userEmail'[/color][COLOR=#990000 ]))[/color] [b][COLOR=#0000FF ]return[/color][/b] false[COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]save[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ]([/color][b][COLOR=#000000 ]strlen[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]getPrimary[/color][/b][COLOR=#990000 ]())[/color] [COLOR=#990000 ]>[/color] [COLOR=#993399 ]0[/color] [COLOR=#990000 ]):[/color]
[tab][tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]sendEmail[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'welcome'[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][b][COLOR=#0000FF ]return[/color][/b] true[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]else[/color][/b][COLOR=#990000 ]:[/color]
[tab][tab][tab][b][COLOR=#0000FF ]return[/color][/b] false[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]regeneratePassword[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]key [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]generateRandomAlphaNumericString[/color][/b][COLOR=#990000 ]([/color][COLOR=#993399 ]6[/color][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]userPassword [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]crypt[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]key[COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]save[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]sendEmail[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'resetpassword'[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] true[COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]forgotPassword[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#0000FF ]isset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'userEmail'[/color][COLOR=#990000 ]])):[/color]
[tab][tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]loadFromEmail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'userEmail'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ]([/color][b][COLOR=#000000 ]strlen[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]getPrimary[/color][/b][COLOR=#990000 ]())[/color] [COLOR=#990000 ]>[/color] [COLOR=#993399 ]0[/color] [COLOR=#990000 ]):[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]regeneratePassword[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#0000FF ]return[/color][/b] false[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]sendEmail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$template[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#000000 ]ob_start[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#000080 ]require[/color][/b] TEMPLATE [COLOR=#990000 ].[/color][COLOR=#FF0000 ]'emailtemplates'[/color] [COLOR=#990000 ].[/color] DIRECTORY_SEPARATOR [COLOR=#990000 ].[/color] [b][COLOR=#000000 ]strtolower[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$template[/color][COLOR=#990000 ])[/color] [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'.php'[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$content[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]ob_get_contents[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][COLOR=#009900 ]$textContent[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]strip_tags[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$content[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#000000 ]ob_end_clean[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#000080 ]require_once[/color][/b] BASE [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'classes'[/color] [COLOR=#990000 ].[/color] DIRECTORY_SEPARATOR [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'class.smtp.php'[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#000080 ]require_once[/color][/b] BASE [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'classes'[/color] [COLOR=#990000 ].[/color] DIRECTORY_SEPARATOR [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'class.phpmailer.php'[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#000080 ]require_once[/color][/b] BASE [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'classes'[/color] [COLOR=#990000 ].[/color] DIRECTORY_SEPARATOR [COLOR=#990000 ].[/color] [COLOR=#FF0000 ]'class.pop3.php'[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$mail[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] [b][COLOR=#000000 ]phpmailer[/color][/b][COLOR=#990000 ]([/color]true[COLOR=#990000 ]);[/color]
[tab][tab]try[COLOR=#FF0000 ]{[/color]
[tab][tab][tab][COLOR=#009900 ]$mail[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]AddReplyTo[/color][/b][COLOR=#990000 ]([/color]ADMINEMAILADDRESS[COLOR=#990000 ]);[/color]
[tab][tab][tab][COLOR=#009900 ]$mail[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]setFrom[/color][/b][COLOR=#990000 ]([/color]ADMINEMAILADDRESS[COLOR=#990000 ]);[/color]
[tab][tab][tab][COLOR=#009900 ]$mail[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]addAddress[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]userEmail[COLOR=#990000 ],[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]userSurname[COLOR=#990000 ].[/color] [COLOR=#FF0000 ]', '[/color] [COLOR=#990000 ].[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]userFirstName[COLOR=#990000 ]);[/color]
[tab][tab][tab][COLOR=#009900 ]$mail[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]addBCC[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]''[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][i][COLOR=#9A1900 ]//$mail->AltBody = $textContent;[/color][/i]
[tab][tab][tab][COLOR=#009900 ]$mail[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]MsgHTML[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$content[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][COLOR=#009900 ]$mail[/color][COLOR=#990000 ]->[/color]Subject [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]'Email from '[/color] [COLOR=#990000 ].[/color] SITENAME[COLOR=#990000 ];[/color]
[tab][tab][tab][COLOR=#009900 ]$mail[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]send[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][COLOR=#FF0000 ]}[/color][b][COLOR=#000000 ]catch[/color][/b] [COLOR=#990000 ]([/color]phpmailerException [COLOR=#009900 ]$e[/color][COLOR=#990000 ])[/color] [COLOR=#FF0000 ]{[/color]
[tab][tab][tab][b][COLOR=#0000FF ]echo[/color][/b] [COLOR=#009900 ]$e[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]errorMessage[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][COLOR=#FF0000 ]}[/color] [b][COLOR=#000000 ]catch[/color][/b] [COLOR=#990000 ]([/color]Exception [COLOR=#009900 ]$e[/color][COLOR=#990000 ])[/color] [COLOR=#FF0000 ]{[/color]
[tab][tab][tab][b][COLOR=#0000FF ]echo[/color][/b] [COLOR=#009900 ]$e[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]getMessage[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][COLOR=#FF0000 ]}[/color]   
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]isAuthorised[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$level[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]userAuthorisationLevel [COLOR=#990000 ]>=[/color] [b][COLOR=#000000 ]intval[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$level[/color][COLOR=#990000 ]);[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]can[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$level[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]isAuthorised[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$level[/color][COLOR=#990000 ]);[/color] 
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]validUser[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$email[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$password[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]global[/color][/b] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$query[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"Select count(*) as c from {$this->table} where userEmail=? and userPassword=?"[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$params[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$email[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]crypt[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$password[/color][COLOR=#990000 ]));[/color]
[tab][tab][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]prepare[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$query[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$pdo[/color][COLOR=#990000 ],[/color] [b][COLOR=#0000FF ]__LINE__[/color][/b][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$result[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]execute[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$params[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$result[/color] [COLOR=#990000 ]===[/color] false[COLOR=#990000 ])[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]bail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$s[/color][COLOR=#990000 ],[/color] [b][COLOR=#0000FF ]__LINE__[/color][/b][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$row[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]fetchObject[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] [b][COLOR=#000000 ]intval[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$row[/color][COLOR=#990000 ]->[/color]c[COLOR=#990000 ])[/color] [COLOR=#990000 ]===[/color] [COLOR=#993399 ]1[/color][COLOR=#990000 ];[/color] 
[tab][COLOR=#FF0000 ]}[/color]
[COLOR=#FF0000 ]}[/color]
[COLOR=#990000 ]?>[/color]

Code:
[COLOR=#990000 ]<?php[/color]
[b][COLOR=#0000FF ]class[/color][/b] currentuser [b][COLOR=#0000FF ]extends[/color][/b] user [COLOR=#FF0000 ]{[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]__construct[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab]parent[COLOR=#990000 ]::[/color][b][COLOR=#000000 ]__construct[/color][/b][COLOR=#990000 ]();[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]isLoggedIn[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#0000FF ]isset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_SESSION[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'loggedIn'[/color][COLOR=#990000 ]])):[/color]
[tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ](![/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]expired[/color][/b][COLOR=#990000 ]()):[/color]
[tab][tab][tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]updateLogin[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]loadFromID[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_SESSION[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'userID'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]return[/color][/b] true[COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#0000FF ]else[/color][/b][COLOR=#990000 ]:[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]unset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_SESSION[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'loggedIn'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]return[/color][/b] false[COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]else[/color][/b][COLOR=#990000 ]:[/color]
[tab][tab][tab][b][COLOR=#0000FF ]return[/color][/b] false[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]private [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]updateLogin[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][COLOR=#009900 ]$_SESSION[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'lastLogInTime'[/color][COLOR=#990000 ]][/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]time[/color][/b][COLOR=#990000 ]();[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]private [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]expired[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ](![/color][b][COLOR=#0000FF ]isset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_SESSION[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'lastLogInTime'[/color][COLOR=#990000 ]]))[/color] [b][COLOR=#0000FF ]return[/color][/b] true[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#000000 ]strtotime[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]"+1 hour"[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$_SESSION[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'lastLogInTime'[/color][COLOR=#990000 ]])[/color] [COLOR=#990000 ]<[/color] [b][COLOR=#000000 ]time[/color][/b][COLOR=#990000 ]())[/color] [b][COLOR=#0000FF ]return[/color][/b] true[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] false[COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]logIn[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][i][COLOR=#9A1900 ]//return true;[/color][/i]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]isLoggedIn[/color][/b][COLOR=#990000 ]())[/color] [b][COLOR=#0000FF ]return[/color][/b] true[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ](![/color][b][COLOR=#0000FF ]isset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'userEmail'[/color][COLOR=#990000 ]]))[/color] [b][COLOR=#0000FF ]return[/color][/b] false[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ](![/color][b][COLOR=#0000FF ]isset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'userPassword'[/color][COLOR=#990000 ]]))[/color] [b][COLOR=#0000FF ]return[/color][/b] false[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]validUser[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'userEmail'[/color][COLOR=#990000 ]][/color] [COLOR=#990000 ],[/color] [COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'userPassword'[/color][COLOR=#990000 ]])):[/color]
[tab][tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]updateLogin[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]loadFromEmail[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'userEmail'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][tab][COLOR=#009900 ]$_SESSION[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'loggedIn'[/color][COLOR=#990000 ]][/color] [COLOR=#990000 ]=[/color] true[COLOR=#990000 ];[/color]
[tab][tab][tab][COLOR=#009900 ]$_SESSION[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'userID'[/color][COLOR=#990000 ]][/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]getPrimary[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][b][COLOR=#0000FF ]return[/color][/b] true[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]else[/color][/b][COLOR=#990000 ]:[/color]
[tab][tab][tab][b][COLOR=#0000FF ]return[/color][/b] false[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]logOut[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]unset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_SESSION[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'loggedIn'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][b][COLOR=#0000FF ]unset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_SESSION[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'lastLogInTime'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][b][COLOR=#000000 ]session_write_close[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#000000 ]header[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]"Location: "[/color] [COLOR=#990000 ].[/color] INDEX[COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]exit[/color][/b][COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]
[COLOR=#FF0000 ]}[/color]
[COLOR=#990000 ]?>[/color]

and on the occasions that I need a set of all entities in their object forms I use this factory pattern

Code:
[COLOR=#990000 ]<?php[/color]

[b][COLOR=#0000FF ]class[/color][/b] factory [COLOR=#FF0000 ]{[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]getAll[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$class[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]global[/color][/b] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$return[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][COLOR=#009900 ]$c[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] [COLOR=#009900 ]$class[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]prepare[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'Select * from '[/color][COLOR=#990000 ].[/color] [COLOR=#009900 ]$c[/color][COLOR=#990000 ]->[/color]table[COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]execute[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#0000FF ]while[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$row[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]fetchObject[/color][/b][COLOR=#990000 ]()):[/color]
[tab][tab][tab][COLOR=#009900 ]$c[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] [COLOR=#009900 ]$class[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][COLOR=#009900 ]$c[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]load[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$row[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][COLOR=#009900 ]$return[/color][COLOR=#990000 ][][/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$c[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]endwhile[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#009900 ]$return[/color][COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]   
[COLOR=#FF0000 ]}[/color]
[COLOR=#990000 ]?>[/color]

[COLOR=#009900 ]$users[/color] [COLOR=#990000 ]=[/color] Factory[COLOR=#990000 ]::[/color][b][COLOR=#000000 ]getAll[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'user'[/color][COLOR=#990000 ]);[/color]
 
the factory pattern got split off. here it is again.

Code:
[COLOR=#990000 ]<?php[/color]

[b][COLOR=#0000FF ]class[/color][/b] factory [COLOR=#FF0000 ]{[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]getAll[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$class[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]global[/color][/b] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$return[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][COLOR=#009900 ]$c[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] [COLOR=#009900 ]$class[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$s[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$pdo[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]prepare[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'Select * from '[/color][COLOR=#990000 ].[/color] [COLOR=#009900 ]$c[/color][COLOR=#990000 ]->[/color]table[COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]execute[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#0000FF ]while[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$row[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$s[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]fetchObject[/color][/b][COLOR=#990000 ]()):[/color]
[tab][tab][tab][COLOR=#009900 ]$c[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] [COLOR=#009900 ]$class[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][COLOR=#009900 ]$c[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]load[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$row[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][COLOR=#009900 ]$return[/color][COLOR=#990000 ][][/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$c[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]endwhile[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#009900 ]$return[/color][COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]
[COLOR=#FF0000 ]}[/color]
[COLOR=#990000 ]?>[/color]
 
Wow, that's a lot of information! I'll digest it slowly when it's not after midnight (here in Japan).

FWIW, I'm gradually reading a book about PHP OOP style, and I'm hoping someday to convert this application to it, but it will require a rewrite from the ground up, which I don't have time for at the moment. This app is indeed in that second category you mentioned: a bigger, longer-term interface that accesses a complex relational database and would definitely be easier to maintain with that style of programming. But the old procedural style (in any language) is so ingrained in me that I have trouble thinking any other way. I manage to muddle through Javascript and jQuery, which are OOP at the core, but I mostly still think the same 'ol way and just change the syntax around ("form.submit()" instead of "submit(form)"). I'm not a young dog anymore, and you know what they say about old dogs and new tricks...
 
Your __()/gdgettext solution looks nice (assuming that there isn't a way that doesn't require changing all the _() calls, which I get the impression there isn't). But I have one question about it: If I change all the instances of _() in my code to __(), how will PoEdit react? I'm concerned that it will consider everything obsolete and start over, because it might only see one gettext() call instead of hundreds.

I already have enough trouble with PoEdit in that regard when I make small changes to some of the English and then choose Update Catalog - I would rather it just declare everything fuzzy so that I can reference the previous Japanese, but it always wants to throw some things away that are just changed rather than removed from my code. This is a bit off-topic, but if someone knows how to get PoEdit to be less trashcan-happy, I'm all ears. (Or if you want to recommend a better tool than PoEdit...)
 
sorry, i have never used poedit. easy enough, i assume, to extract a page from your app and run the script on it?

I assume that poedit will simply be a wrapper for common scripts like xgettext. this uses common keywords to extract strings from source files and yes, you will have to add __ to the list of accepted keywords. you can supply the keywords as part of the invocation of xgettext. something like this

Code:
--keyword='__, _, gettext, dgettext:2, dcgettext:2, ngettext:1,2, dngettext:2,3, dcngettext:2,3'

or it would be easy enough to write a regex to extract the strings for you

Code:
$pattern = "|__\s*\(\s*('|\")(.*?)\\1\s*\)|im";
you'd have to build a script that loops over the php files in your sites folders but that's not difficult. plenty of examples in the readdir manual entry.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top