Location: PHPKode > projects > Gsys > admin/pledge_functions.php
<?PHP
//Filename : pledge_functions.php
//Description : Functions for working on pledges
//Author :  darc
//Last modified :  2006.12.20

    include '../includes/auth_pledge_ed.php';  //authenticate
    include '../includes/db.php'; //setup database

switch($_GET["cat"])
{
    case "add" :
    {
      //Check to make sure all required fields were filled
      if(!$_POST[l_name] || !$_POST[f_name] || !$_POST[username] || !$_POST[email] || !$_POST[ssn] || !$_POST[stu_num]  || !$_POST[password])
      {
        echo "Required fields not completed!  Press back in your browser window.";
        exit;
      }

      $sql ="SELECT * FROM $table_name WHERE username = '$_POST[username]';";
      $result = mysql_query($sql,$connection) or die(mysql_error());
      $num = mysql_num_rows($result);
      //Check if the requested username exists
      //This should probably be changed to automagically use (first initial)(last name) then check to see if it exists.
      if($num != 0)
      {
        echo "Username Exists!  Press back and choose another.";
        exit;
      }

    //Setup variables to insert into database
      $l_name = $_POST[l_name];
      $f_name = $_POST[f_name];
      $m_name = $_POST[m_name];
      $username = $_POST[username];
      $password = $_POST[password];
      $email = $_POST[email];
      $nickname = $_POST[nickname];
      $phone = $_POST[phone];
      $address = $_POST[address];
      $town = $_POST[town];
      $state = $_POST[state];
      $zip = $_POST[zip];
      $ssn = $_POST[ssn];
      $stu_num = $_POST[stu_num];
      $dob = $_POST[dob];
      $on_off_campus = $_POST[on_off_campus];
      $status = "pledge"; //Set authentication to pledge

//Perform query to insert pledge
      $sql ="INSERT INTO $table_name (l_name, f_name, m_name, username, password, email, nickname, phone, address, town, state, zip, ssn, stu_num, dob, on_off_campus, status) VALUES ('$l_name', '$f_name', '$m_name', '$username', PASSWORD('$password'), '$email', '$nickname', '$phone', '$address', '$town', '$state', '$zip', AES_ENCRYPT( '$ssn', '46eastlawn'), '$stu_num', '$dob', '$on_off_campus', '$status');";
      mysql_query($sql,$connection) or die(mysql_error());

      echo "Pledge $l_name, $f_name successfully added to database with username \"$username\".";
      echo "<a href=\"pledge_man.php\">Return Pledge Administration</a>";
      break;
    }

//Delete a pledge
    case "del" :
    {
        $username = $_POST[username];
        $sql ="DELETE FROM $table_name WHERE username = '$username';";
        $result = mysql_query($sql,$connection) or die(mysql_error());

        echo "Pledge with username:  $username, DELETED from database.";
        echo "<a href=\"pledge_man.php\">Return Pledge Administration</a>";
        break;
    }

//Initiate a pledge - giving them brother authentication status
    case "initiate" :
    {
        $username = $_POST[username];
        $sql ="UPDATE `brothers` SET `status` = 'active' WHERE `username` ='$username';";
        $result = mysql_query($sql,$connection) or die(mysql_error());

        echo "Pledge with username:  $username, is now recorded as an active brother.";
        echo "<a href=\"pledge_man.php\">Return Pledge Administration</a>";
        break;
    }

//Default case, error
    default :
    {
      echo "No instructions supplied...";
      break;
    }
}
?>
Return current item: Gsys