Encryptorwhereion Class The Encryption Class provides two-way data encryption. It uses a scheme that pre-compiles the message using a randomly hashed bitwise XOR encoding scheme, which is then encrypted using the Mcrypt library. If Mcrypt is not available on your server the encoded message will still provide a reasonable degree of security for encrypted sessions or other such "light" purposes. If Mcrypt is available, you'll effectively end up with a double-encrypted message string, which should provide a very high degree of security. Setting your Key The key for encryption class is defined in config.php file. $config['encryption_key'] = "o2xda01"; Initialization and Use of Class The encryption class is instantiated using the following syntax: $encrypt = new EncryptionManager(); To encrypt any word/message, use the encode function: $encrypt->encode($message); And to decrypt any encrypted string, use decode
function: $encrypt->decode($encrypted_string); IMPORTANT POINTS 1) The encoded messages the encryption function generates will be approximately 2.6 times longer than the original message. For example, if you encrypt the string "my super secret data", which is 21 characters in length, you'll end up with an encoded string that is roughly 55 characters. Keep this information in mind when selecting your data storage mechanism. Cookies, for example, can only hold 4K of information. 2) The encrypted string generated by encode function is not always same. E.g. if you encrypt a string ‘tech’ twice in a script then output of encode function can be different however the output of decode function will be same i.e ‘tech’. 3) Whenever you pass encrypted string in a url through query string etc, please make sure to use urlencode function because the encrypted string contains several characters which are considered as escape characters in querystring like + etc. So if you pass the encrypted string without urlencode then decode function will generate incorrect results.
ConfigManager Class Configmanager class is used to access constants
defined in config.php file. Initialization and Use of Class Configmanager class is instantiated using the following syntax: $config = ConfigManager::getInstance(); Configmanager class consist of only one function (item) which is used to access any item or constant or setting defined in config.php file. $a = $config->item(‘encryption_key’); This would return the value of $config[‘encryption_key’]. If no such key exist in the config.php file then FALSE is returned.
IMPORTANT POINTS Please note that the config object is already instantiated in common.php file and you can access it using $config variable. So use that object wherever there is need to use it and don’t modify $config variable in your scripts as well, as some base libraries are also using it.
ErrorManager Class This class is used for various error handling functions.
Initialization and Use of Class Errormanager class is instantiated using the following syntax: $error = ErrorManager::getInstance(); The errormanager class consist of following functions: 1) showError: This function is used for displaying any error and halt execution of script. Eg. Critical errors like config file doesn’t exist, incorrect database settings etc. In simple terms, this function is used following way : $error->showError($message); Where $message can be a string or an array. showError also provides you functionality to change the title of error page as well as template and you can use 2nd and 3rd parameters of this function for changing it but you seldom need to use this options. 2) showMessage: This function is for displaying user defined messages e.g Username already exist, profile updates successfully etc. One main advantage of using this function is that all user defined messages will have same look and style and if in any case you need to override the default settings you can use parameters of this function ie. $error->showMessage($message, ‘
’, ‘
’);
Where ‘
’ and ‘
’ defines the opening and closing tag of message. In simple way this function is used as: $error->showMessage($message); 3) logMessage: This function is used for logging error messages in a log file. This function has 2 parameters: messageType and message. Messagetype indicates which type of message is this like Informational message (INFO), Debug Message(DEBUG) etc. and message parameter is used for actual message. 4) showDBError: This function is used for displaying database error message. The parameters of this function are $sql (i.e the sql query that caused the error) and the actual error message. You might never need to use this function in your scripts as DB class uses this function and will display the sql and message in case of any error.
IMPORTANT POINTS Please note that the error object is already instantiated in common.php file and you can access it using $error variable. So use that object wherever there is need to use it and don’t modify $error variable in your scripts as well, as some base libraries are also using it.
JavascriptManager Class This class is used for simplifying one of the most boring task in form development i.e javascript validation. Using this class you will be able to validate a form by using a php array only. Initialization and Use of Class JavascriptManager class is used in following way: $jscript = new JavascriptManager($formname, $rulesarray, $error_mode ); 1) First parameter $formname specifies the name of form on which validation need to be applied. 2) Second parameter $rulessarray is the set of rules and error messages. You have to define rulesarray in javaScriptRules.php file. The syntax of rulesarray is: $rules['Username'] = array("isEmpty" "Please enter username."); $rules['Password'] = array("isEmpty" "Please enter password.");
=> =>
where ‘Username’ is the filed name, isEmpty is the name of javascript function and other parmeter is the error message. If there are any other additional parameters that need to be passed e.g. in Password and ConfirmPassword then the syntax will be: $rules[‘Password’] ConfirmPassword”
= array(“isNotEqual| => “Your passwords do not
match”); So this function will work using 2 parameters Password and ConfirmPassword. Ie. All additional parameters must be written with function name separated by pipe (|) symbol. The functions that you can use are: Function isEmpty isNumeric isOfExactLength isOfMinLength isOfMaxLength isAtleastOneNotEmpty isNotEqual isValidEmail isSelected
Use Checks whether a field is empty or not Checks whether a field value is numeric or not Checks whether a field has exactly n number of characters Checks whether a field has minimum n number of characters Checks whether a field has maximum n number of characters Checks whether the value of either of the two control is blank or not Check whether the value of two control equals or not Check whether an Email address is valid Check whether the
isMultipleSel isChecked
something is selected in the list or not Check whether the something is selected in the multi select list or not Check whether a checkbox or radio button is checked or not.
The 3rd parameter is a constant with values SINGLE_ALERT or MULTIPLE_ALERT. Single alert means that your error messages will be in collective format i.e Sorry, we cannot complete your request. Please provide us the missing or incorrect information mentioned below: Please enter username. Please enter passwords. and in MULTIPLE_ALERT, separate alerts will be generated. The default option is SINGLE_ALERT. 1)
Define pagename variable in controller file i.e $pagename = “addUser”; 2) Define a rule array in javaScriptRules.php file for $pagename variable. 3) Instantiate the javascript class in controller file i.e
$javascript = new JavaScriptManager(‘form1’, $rules, SINGLE_ALERT); 4) Call the validate function and store output in variable $validate = $javascript->getValidationStr(); 5) Print this validate variable in your view or template file in between head section i.e at runtime, this validate variable will be converted in javascript code with validation file included and with validation file. 6) Don’t forget to add $javascript-> getFormStr() function in your form tag ie.