reSIProcate/repro  9694
Functions | Variables
reprofunctions.php File Reference

Go to the source code of this file.

Functions

 dbgShowBroswer ($data, $return_str=false, $func="print_r")
 dbgShowFile ($data, $func="print_r")
 dbgSquirt ($s, $stamp=1)
 validateUser ($u, $p)
 getUserState ($user, $code)
 usernameInUse ($u)
 createAccount ($username, $passwordMD5, $fullname, $domain, $email, $activationCode)
 activateUser ($username, $activationCode)
 matchUserAndEmail ($username, $email)
 createResource ($username, $aor, $forwardType, $forwardDestination, $voicemail)
 lookupUserInformation ($username, &$id, &$fullname, &$domain, &$email)
 getResourcesByUsername ($username, &$resources)
 getSalt (&$salt)
 clearCookies ()
 checkCookies (&$forceLogin, &$error, $ignoreBlanks)
 updateFullname ($username, $newFullname)
 createPassword ($username, $password)
 updatePassword ($username, $newPassword)
 updateEmail ($username, $newEmail)
 deleteResource ($username, $resourceId)
 updateResource ($resourceId, $username, $resource, $forwardType, $forward, $voicemail)

Variables

 $provider = "XYZ"
 $providerEmail = "XYZ Activation <activation@xyz.com>"
 $sessionDuration = 600

Function Documentation

activateUser ( username,
activationCode 
)

Definition at line 189 of file reprofunctions.php.

                                                  {
    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
    mysql_select_db("repro",$db) or die (mysql_error());
    $activationDate = date("Y-m-d");
    $query="update Users set state = 'A' where username = '$username' and activationCode = '$activationCode'";

    $result = mysql_query($query) or die(mysql_error());

        $count = mysql_affected_rows();
        
    if ((1 == $count) && (TRUE == $result)) {
        // no error and 1 row updated
        $state = TRUE;
    } else {
                $state = FALSE; }
                
        mysql_close($db);
        return $state;
}
checkCookies ( &$  forceLogin,
&$  error,
ignoreBlanks 
)

Definition at line 434 of file reprofunctions.php.

                                                          {
  $forceLogin = TRUE;
  $error = "";
  global $sessionDuration;

  dbgSquirt("==============Function: checkCoookies ==============");
  dbgSquirt('Cookie --' . dbgShowFile($_COOKIE));

  if (isset($_COOKIE['user']) && !empty($_COOKIE['user']) &&
      isset($_COOKIE['authentication']) && !empty($_COOKIE['authentication'])) {
    // both user and authentication cookies are set and non-blank
    // dbgSquirt("Cookies set and non-empty");
    $userCookie = $_COOKIE['user'];
    $authenticationCookie = $_COOKIE['authentication'];
    $time = time();

    // dbgSquirt("Getting salt");
    if (getSalt($salt)) {
      // dbgSquirt("...salt gotten");
      // dbgSquirt("Encrypting");
      if (sha1($userCookie . $salt) == $authenticationCookie) {
        // authentication passed
        // so reset expiration on cookies
        // dbgSquirt("Cookie matches encryption");
        // dbgSquirt("Resetting cookies");
        // dbgSquirt("Time -- $time");
        // dbgSquirt("Time + Duration -- ". ($time+$sessionDuration));
        $result = setcookie("user",$userCookie,$time+$sessionDuration);
        $result1 = setcookie("authentication",$authenticationCookie,
                             $time+$sessionDuration);
        if ((TRUE == $result) && (TRUE == $result1)) {
          // everything worked
          // dbgSquirt("Everything worked ... no need to forceLogin");
          $forceLogin = FALSE;
        } else {
          $error = "Internal error -- problem while creating cookies.  Please contact an administrator.";
        }
      } else {
        // credentials in cookies don't match.
        // dbgSquirt("Cookie does NOT match encryption");
        $error = "Authentication error -- The supplied credentials don't match our stored values. Please reauthenticate and try again.";
      }
    } else {
      // dbgSquirt("...error while getting salt");
      // error while trying to get salt value
      $error = "Internal error -- unable to validate supplied credentials. Please reauthenticate and try again.";
    }
  } else {
    // cookies were unset or contained empty values
    // dbgSquirt("Cookies unset or empty");
    if (FALSE == $ignoreBlanks) {
      $error = "Please log in."; }
  }

  dbgSquirt("Returning -- ". empty($error));
  return(empty($error));
}
clearCookies ( )

Definition at line 402 of file reprofunctions.php.

                        {

dbgSquirt("==============Function: Clear Cookies ==============");
dbgSquirt('Cookie --' . dbgShowFile($_COOKIE));


  $result = setcookie("user","",mktime(12,0,0,1,1,1970));
  $result1 = setcookie("authentication","",mktime(12,0,0,1,1,1970));

  return ($result && $result1);
}
createAccount ( username,
passwordMD5,
fullname,
domain,
email,
activationCode 
)

Definition at line 163 of file reprofunctions.php.

                                                                                            {
    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
    mysql_select_db("repro",$db) or die (mysql_error());
    $activationDate = date("Y-m-d");
    $query="insert into Users (username,password,fullname,domain,email,state,activationDate,activationCode) values('$username','$passwordMD5','$fullname','$domain','$email','U','$activationDate','$activationCode')";

    $result = mysql_query($query) or die(mysql_error());

        $count = mysql_affected_rows();
        
    if ((1 == $count) && (TRUE == $result)) {
        // no error and 1 row inserted
        $state = TRUE;
    } else {
                $state = FALSE; }
                
        mysql_close($db);
        return $state;
}
createPassword ( username,
password 
)

Definition at line 522 of file reprofunctions.php.

createResource ( username,
aor,
forwardType,
forwardDestination,
voicemail 
)

Definition at line 242 of file reprofunctions.php.

                                                                                        {
    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
    mysql_select_db("repro",$db) or die (mysql_error());

    // first we need to get the userid from the username
    $query="select id from Users where username = '$username'";
    $result = mysql_query($query) or die(mysql_error());

    $count=mysql_num_rows($result);
    if ($count == 1) {
      // we matched, so lets get the userid of the user
      $userid = mysql_result($result,0,"id");
      mysql_free_result($result);
        
      // if there are any constraints (e.g. AOR must be unique, etc, check
      // for them here
                
      // add the resource to the Resources table
      $query = "insert into Resources (userid,aor,forwardType,forwardDestination,voicemail) values($userid,'$aor','$forwardType','$forwardDestination','$voicemail')";
                
      $result = mysql_query($query) or die(mysql_error());
      $count = mysql_affected_rows();
        
      if ((1 == $count) && (TRUE == $result)) {
        // no error and 1 row inserted
        $state = TRUE;
      } else {
        $state = FALSE; }
    } else {
      $state = FALSE; }

    mysql_free_result($result);
    mysql_close($db);
    return $state;
}
dbgShowBroswer ( data,
return_str = false,
func = "print_r" 
)

Definition at line 27 of file reprofunctions.php.

                                                                      {
   ob_start();
   $func($data);
   $output = '<pre>'.htmlspecialchars(ob_get_contents()).'</pre>';
   ob_end_clean();
   if($return_str) {
     return $output; 
   } else {
     echo $output;
     return("");
   }
}
dbgShowFile ( data,
func = "print_r" 
)

Definition at line 47 of file reprofunctions.php.

                                              {
   ob_start();
   $func($data);
   $output = ob_get_contents();
   ob_end_clean();
   return $output; 
}
dbgSquirt ( s,
stamp = 1 
)

Definition at line 60 of file reprofunctions.php.

                                 {
  $fp = fopen ("/tmp/squirt", "a+");
  if ($stamp == 1) {
    fputs($fp, date('ymd H:i:s '));
  }
  fputs($fp, $s."\n");
  fclose($fp);
}
deleteResource ( username,
resourceId 
)

Definition at line 595 of file reprofunctions.php.

                                                {
  dbgSquirt("============= Function: deleteResource ===========");

  $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
  mysql_select_db("repro",$db) or die (mysql_error());

  // first we need to get the userid from the username
  $query="select id from Users where username = '$username'";
  dbgSquirt("Query -- $query");
  $result = mysql_query($query) or die(mysql_error());

    $count=mysql_num_rows($result);
    dbgSquirt("Rows -- $count");
    if ($count == 1) {
      // we matched, so lets get the userid of the user
      $userid = mysql_result($result,0,"id");
      mysql_free_result($result);
        
      // delete the resource
      $query = "delete from Resources where userid = '$userid' and id = '$resourceId'";
      dbgSquirt("Query2 -- $query");

      $result = mysql_query($query) or die(mysql_error());
      $count = mysql_affected_rows();

      dbgSquirt("Rows -- $count");      
      if ((1 == $count) && (TRUE == $result)) {
        // no error and 1 row deleted (should only be 1 row since id is
        // the primary key)
        $state = TRUE;
      } else {
        $state = FALSE; }
    } else {
      $state = FALSE; }

    mysql_free_result($result);
    mysql_close($db);
    return $state;
}
getResourcesByUsername ( username,
&$  resources 
)

Definition at line 324 of file reprofunctions.php.

                                                       {
    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
    mysql_select_db("repro",$db) or die (mysql_error());

    // first we need to get the userid from the username
    $query="select id from Users where username = '$username'";
    $result = mysql_query($query) or die(mysql_error());

    $count=mysql_num_rows($result);
    // print "Query -- $query<br />\nCount -- $count<br >\n";
    
    if ($count == 1) {
        // we matched, so lets get the userid of the user
        $userid = mysql_result($result,0,"id");
        mysql_free_result($result);
        
        $query = "select id,aor,forwardType,forwardDestination,voicemail from Resources where userid = '$userid'";
        $result = mysql_query($query) or die(mysql_error());
        
        // print "Query -- $query<br />\nResult -- $result<br />\n";

                $state = TRUE;
                while (($myrow = mysql_fetch_array($result))) {
                        // print "Row -- ";
                        // print_r($myrow);
                        $newRow = array($myrow['id'],$myrow['aor'],$myrow['forwardType'],$myrow['forwardDestination'],$myrow['voicemail']);

                        // print "<br />New Row --";
                        // print_r($newRow);
                        $resources[] = $newRow;
                        // print "<br />Resource -- ";
                        // print_r($resources);
                }
    } else {
        $state = FALSE;
        }
    
    mysql_free_result($result);
        mysql_close($db);
        return $state;
}
getSalt ( &$  salt)

Definition at line 374 of file reprofunctions.php.

                         {
    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
    mysql_select_db("repro",$db) or die (mysql_error());
    $query="select value from Parameters where parameter='salt'";
    $result = mysql_query($query) or die(mysql_error());
    
    $count=mysql_num_rows($result);
    
    if ($count == 1) {
        // we matched, so lets get the state of the user
        $salt = mysql_result($result,0,"value");
        $state = TRUE;
    } else {
                $salt = ""; 
                $state = FALSE; }
                
    mysql_free_result($result);
        mysql_close($db);
        return $state;
}
getUserState ( user,
code 
)

Definition at line 108 of file reprofunctions.php.

                                    {
    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
    mysql_select_db("repro",$db) or die (mysql_error());
    $query="select * from Users where username='$user' and activationCode='$code'";
    $result = mysql_query($query) or die(mysql_error());
    
    $count=mysql_num_rows($result);
    
    if ($count == 1) {
        // we matched, so lets get the state of the user
        $state = mysql_result($result,0,"state");
    } else {
                $state = "N"; }
                
    mysql_free_result($result);
        mysql_close($db);
        return $state;
}
lookupUserInformation ( username,
&$  id,
&$  fullname,
&$  domain,
&$  email 
)

Definition at line 290 of file reprofunctions.php.

                                                                           {
    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
    mysql_select_db("repro",$db) or die (mysql_error());
    $query="select * from Users where username='$username'";
    $result = mysql_query($query) or die(mysql_error());
    
    $count=mysql_num_rows($result);
    
    if ($count == 1) {
        // we matched, so lets get the state of the user
        $id = mysql_result($result,0,"id");
        $fullname = mysql_result($result,0,"fullname");
        $domain = mysql_result($result,0,"domain");
        $email = mysql_result($result,0,"email");

        $state = TRUE;
    } else {
                $state = FALSE; }
                
    mysql_free_result($result);
        mysql_close($db);
        return $state;
}
matchUserAndEmail ( username,
email 
)

Definition at line 218 of file reprofunctions.php.

                                             {
    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
    mysql_select_db("repro",$db) or die (mysql_error());
    $query="select * from Users where username='$username' and email='$email' and state = 'A'";
    $result = mysql_query($query) or die(mysql_error());
    
    $count=mysql_num_rows($result);
    if ($count == 1) {
        // we matched, so that user/email combination is valid
        $state = TRUE;
    } else {
                $state = FALSE; }
                
        mysql_free_result($result);
        mysql_close($db);
        return $state;
}
updateEmail ( username,
newEmail 
)

Definition at line 563 of file reprofunctions.php.

                                           {
  dbgSquirt("============= Function: updateEmail ===========");

  $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
  mysql_select_db("repro",$db) or die (mysql_error());
  $query="update Users set email = '$newEmail' where username = '$username'";
  dbgSquirt("Query -- $query");

  $result = mysql_query($query) or die(mysql_error());
    
  $count = mysql_affected_rows();
        
  if ((1 == $count) && (TRUE == $result)) {
    // no error and 1 row updated
    $state = TRUE;
  } else {
    $state = FALSE; }
                
  mysql_close($db);
  return $state;
}
updateFullname ( username,
newFullname 
)

Definition at line 498 of file reprofunctions.php.

                                                 {
    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
    mysql_select_db("repro",$db) or die (mysql_error());
    $query="update Users set fullname = '$newFullname' where username = '$username'";

    $result = mysql_query($query) or die(mysql_error());

    $count = mysql_affected_rows();
        
    if ((1 == $count) && (TRUE == $result)) {
        // no error and 1 row updated
      $state = TRUE;
    } else {
      $state = FALSE; }
                
    mysql_close($db);
    return $state;
}
updatePassword ( username,
newPassword 
)

Definition at line 535 of file reprofunctions.php.

                                                 {
  dbgSquirt("============= Function: updatePassword ===========");

  $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
  mysql_select_db("repro",$db) or die (mysql_error());
  $query="update Users set password = '$newPassword' where username = '$username'";
  dbgSquirt("Query -- $query");

  $result = mysql_query($query) or die(mysql_error());
    
  $count = mysql_affected_rows();
        
  if ((1 == $count) && (TRUE == $result)) {
    // no error and 1 row updated
    $state = TRUE;
  } else {
    $state = FALSE; }
                
  mysql_close($db);
  return $state;
}
updateResource ( resourceId,
username,
resource,
forwardType,
forward,
voicemail 
)

Definition at line 641 of file reprofunctions.php.

                                             {
  dbgSquirt("============= Function: updateResource ===========");

  $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
  mysql_select_db("repro",$db) or die (mysql_error());

  // first we need to get the userid from the username
  $query="select id from Users where username = '$username'";
  dbgSquirt("Query -- $query");
  $result = mysql_query($query) or die(mysql_error());

  $count=mysql_num_rows($result);
  dbgSquirt("Rows -- $count");
  if ($count == 1) {
    // we matched, so lets get the userid of the user
    $userid = mysql_result($result,0,"id");
    mysql_free_result($result);
        
    // delete the resource
    $query = "update Resources set aor='$resource',forwardType='$forwardType',forwardDestination='$forward',voicemail='$voicemail' where userid = '$userid' and id = '$resourceId'";
    dbgSquirt("Query2 -- $query");

    $result = mysql_query($query) or die(mysql_error());
    $count = mysql_affected_rows();

    dbgSquirt("Rows -- $count");        
    if ((1 == $count) && (TRUE == $result)) {
      // no error and 1 row modified (should only be 1 row since id is
      // the primary key)
      $state = TRUE;
    } else {
      $state = FALSE; }
  } else {
    $state = FALSE; }

  mysql_free_result($result);
  mysql_close($db);
  return $state;
}
usernameInUse ( u)

Definition at line 137 of file reprofunctions.php.

                           {
    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
    mysql_select_db("repro",$db) or die (mysql_error());
    $query="select * from Users where username='$u'";
    $result = mysql_query($query) or die(mysql_error());
    
    $count=mysql_num_rows($result);
    if ($count == 1) {
        // we matched, so that name is in use
        $state = "Y";
    } else {
                $state = "N"; }
                
        mysql_free_result($result);
        mysql_close($db);
        return $state;
}
validateUser ( u,
p 
)

Definition at line 79 of file reprofunctions.php.

                              {
    $db = mysql_connect("localhost","apache","apache") or die(mysql_error());
    mysql_select_db("repro",$db) or die (mysql_error());
    $query="select * from Users where username='$u' and password='$p'";
    $result = mysql_query($query) or die(mysql_error());
    
    $count=mysql_num_rows($result);
    
    if ($count == 1) {
        // we matched, so lets get the state of the user
        $state = mysql_result($result,0,"state");
    } else {
                $state = "N"; }
                
    mysql_free_result($result);
        mysql_close($db);
        return $state;
}

Variable Documentation

$provider = "XYZ"

Definition at line 15 of file reprofunctions.php.

$providerEmail = "XYZ Activation <activation@xyz.com>"

Definition at line 16 of file reprofunctions.php.

$sessionDuration = 600

Definition at line 17 of file reprofunctions.php.