Computer Operations/Database/Functions/Data Conversion

From MFIWiki
(Difference between revisions)
Jump to: navigation, search
 
m
 
Line 44: Line 44:
 
:}
 
:}
 
<br>
 
<br>
This function determines the status of an individual's password.  A password can have only one of three possible status.  "Not Set" typically occurs with older MFI members who have been entered into the DB but were never assigned a password.  They typically lack a username as well. "Set but not Encoded" means that the password in has been created by Membership or a CC member.  This is done with a random password generator function and is part of either the Welcome Letter generation (from the dbnewmember module) or the password is reset in the dbpasswordreset module.<br>  The password is typically retrieved from the DB via a function and then sent to this function for checking.
+
This function determines the status of an individual's password.  A password can have only one of three possible status.  "Not Set" typically occurs with older MFI members who have been entered into the DB but were never assigned a password.  They typically lack a username as well. "Set but not Encoded" means that the password has been created by Membership or a CC member.  This is done with a random password generator function and is part of either the Welcome Letter generation (from the dbnewmember module) or the password is reset in the dbpasswordreset module.<br>  The password is typically retrieved from the DB via a function and then sent to this function for checking.
 
:function passwordstatus($pass) {
 
:function passwordstatus($pass) {
 
::if ($pass == NULL){
 
::if ($pass == NULL){
Line 65: Line 65:
 
:}
 
:}
 
<br>
 
<br>
These next two functions are identical save for the data they retrieve for conversion.  An id number is sent to the corresponding to either an area ID or a contact type ID.  These then retrieve the name from the proper table that matches that ID and returns it.  Although only one result is returned since the potential for multiple results is there, we have to pull out the result from the subarray.<br>
+
These next two functions are identical save for the data they retrieve for conversion.  An id number is sent to the function, corresponding to either an area ID or a contact type ID.  These then retrieve the name from the proper table that matches that ID and returns it.  Although only one result is returned, since the potential for multiple results is there, we have to pull out the result from the subarray.<br>
 
:function getareaname($id) {
 
:function getareaname($id) {
 
::$sql="SELECT `name` FROM `area` WHERE `id` = '".$id."'";
 
::$sql="SELECT `name` FROM `area` WHERE `id` = '".$id."'";

Latest revision as of 23:30, 30 January 2009

On some of our pages for viewing and/or editing service records, the words "Yes" or "No" are displayed and are sent by the form to the code. The DB tables use the "1" and "0" respectively for storing the data. This function converts the word to the number.

function yesnocheck($value) {
if ($value == "Yes") {
$value = 1;
}elseif ($value == "No") {
$value = 0;
}
return $value;
}


Like the previous function this function converts from one form to another. However, typically this converts the function for displaying onto the user's screen. It may also be used in converting one value to another for use in the Recent Changes table.

function activeconverter($value) {
if ($value == "Yes" || $value == 1) {
$value = "Active";
}elseif ($value == "No" || $value == 0) {
$value = "Inactive";
}
return $value;
}


This function is used to retrieve a person's picture from the MFIWiki image storage area. This is the reason we insist that individuals and chapters upload the image they want to use for the Wiki and the DB under the title of their member or cell number. Wiki takes the file name and creates an MD5 hash out of it. It then uses the first character of the hash to select a folder and then the first two characters to select a sub-folder. "$type" should typically be either "member" or "chapter". However, we have only provided for the member to be a special option. Otherwise the function defaults to the MFI PD image. So this function can be used if you wish to place that image anywhere else on the page. "$id" is the numeric portion of the either the member's number or the chapter's number. Only the numberic portion of these numbers are ever passed around for the use of the program. To further prevent confusion within the program all chapters are assigned numbers above 100,000.

function picture($type, $id) {
//Determine picture location
if ($type == "member"){
$fullid = "MFI-RM-".$id.".jpg";
}else{
$fullid = "MFI-RC-".$id.".jpg";
}
$hash = md5($fullid);
$pic = 'http://wiki.maquis.com/images/'. $hash{0} . '/' . substr( $hash, 0, 2 ) . '/'.$fullid;
//Check if picture exsists
if (!exec('ls -l ../../wiki/httpdocs/images/'.$hash{0} . '/' . substr( $hash, 0, 2 ) . '/'.$fullid.' | grep '.$fullid)) {
//If not substitute appropriate generatic picture
if ($type == "member"){
$fullid = "Lcars_blnk.jpg";
}else{
$fullid = "Pd_mfi.jpg";
}
$hash = md5($fullid);
$pic = 'http://wiki.maquis.com/images/'. $hash{0} . '/' . substr( $hash, 0, 2 ) . '/'.$fullid;
}
//Return picture location
return $pic;
}


This function determines the status of an individual's password. A password can have only one of three possible status. "Not Set" typically occurs with older MFI members who have been entered into the DB but were never assigned a password. They typically lack a username as well. "Set but not Encoded" means that the password has been created by Membership or a CC member. This is done with a random password generator function and is part of either the Welcome Letter generation (from the dbnewmember module) or the password is reset in the dbpasswordreset module.
The password is typically retrieved from the DB via a function and then sent to this function for checking.

function passwordstatus($pass) {
if ($pass == NULL){
$passhtml = "Password has not been set";
}else{
$encrypt = explode(":",$pass,2);
switch ($encrypt[0]) {
case "md5":
$passhtml = "Set and MD5 encoded";
break;
case "plain":
$passhtml = "Set but not encoded";
break;
default:
$passhtml = "Set with unknown encoding";
break;
}
}
return $passhtml;
}


These next two functions are identical save for the data they retrieve for conversion. An id number is sent to the function, corresponding to either an area ID or a contact type ID. These then retrieve the name from the proper table that matches that ID and returns it. Although only one result is returned, since the potential for multiple results is there, we have to pull out the result from the subarray.

function getareaname($id) {
$sql="SELECT `name` FROM `area` WHERE `id` = '".$id."'";
$result = db_query($sql,$conn);
$areaname = db_fetch_array($result);
$areaname = $areaname[0]["name"];
return $areaname;
}


function contacttype($id) {
$sql="SELECT `type` FROM `contact_type` WHERE `id` = '".$id."'";
$result = db_query($sql,$conn);
$typename = db_fetch_array($result);
$typename = $typename[0]["type"];
return $typename;
}
Personal tools