Location: PHPKode > projects > Gsys > admin/brother_functions.php
<?PHP
//Filename :   brother_functions.php
//Description : Functions for working with/on brothers
//Author :  darc
//Modified from pledge_functions.php by paroxon on 17 aug 06
//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[stu_num]  || !$_POST[password] || !$_POST[initiation_date])
      {
        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];
$initiation_date=$_POST[initiation_date];
$pos=$_POST[pos];
      $on_off_campus = $_POST[on_off_campus];
      $status = "active"; //Set authentication to active

//Perform query to insert brother
      $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, initiation_date, pos) 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', '$initiation_date', '$pos');";
      mysql_query($sql,$connection) or die(mysql_error());

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

          }

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

        echo "Brother with username:  $username, DELETED from database.";
        echo "<a href=\"brother_man.php\">Return Brother Administration</a>";
        break;
    }
case "edit":
{
  	$uname=$_POST[uname];
      $sql ="SELECT * FROM $table_name WHERE username = '$uname';";
      $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.


    //Setup variables to insert into database
      $l_name = $_POST[l_name];
      $f_name = $_POST[f_name];
      $m_name = $_POST[m_name];


      $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];
$initiation_date=$_POST[initiation_date];
$pos=$_POST[pos];
      $on_off_campus = $_POST[on_off_campus];
      $status = "active"; //Set authentication to active

//Perform query to insert brother
      $sql ="UPDATE $table_name SET l_name='$l_name',f_name='$f_name', m_name='$m_name', email='$email', nickname='$nickname', phone='$phone', address='$address', town='$town', state='$state', zip='$zip', ssn='$ssn', stu_num='$stu_num', dob='$dob', on_off_campus='$on_off_campus', initiation_date='$initiation_date', pos='$pos' WHERE username='$uname'";
      mysql_query($sql,$connection) or die(mysql_error());

      echo "Brother $l_name, $f_name successfully updated \"$username\".";
      echo "<a href=\"brother_man.php\">Return Brother Administration</a>";

      break;
}

    case "add_alum" :
    {
      //Check to make sure all required fields were filled
      if(!$_POST[l_name] || !$_POST[f_name] || !$_POST[address])
      {
        echo "Required fields not completed!  Press back in your browser window.";
        exit;
      }

    //Setup variables to insert into database
      $l_name = $_POST[l_name];
      $f_name = $_POST[f_name];
      $m_name = $_POST[m_name];
      $email = $_POST[email];
      $phone = $_POST[phone];
      $address = $_POST[address];
      $town = $_POST[town];
      $state = $_POST[state];
      $zip = $_POST[zip];
	  $initiation_date=$_POST[initiation_date];
      $status = "alumnus"; //Set authentication to active

//Perform query to insert brother 
      $sql ="INSERT INTO $table_name (l_name, f_name, m_name, email, phone, address, town, state, zip, status, initiation_date) VALUES ('$l_name', '$f_name', '$m_name', '$email', '$phone', '$address', '$town', '$state', '$zip', '$status', '$initiation_date');";
      mysql_query($sql,$connection) or die(mysql_error());

	  echo "<html>
		<head><title>Event Added Successfully</title>
		<link href=\"../includes/index.css\" rel=\"stylesheet\" type=\"text/css\"></head>
		<body class=\"body\">
<br />
<table width=\"810\" height=\"626\" border=\"0\" align=\"center\" cellpadding=\"15\">
  <tr> 
    <td height=\"128\" colspan=\"2\"><img src=\"../images/eg_banner.gif\" width=\"810\" height=\"172\"></td>
  </tr>
  <tr> 
    <td width=\"27%\" height=\"488\" valign=\"top\">"; include '../includes/nav.inc'; echo "</td>
    <td width=\"53%\" align=\"center\">Brother $l_name, $f_name successfully added to database.<br>   </td>
  </tr>
</table></body></html>";
      break;
}

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