Booked Scheduler Community Support
December 06, 2019, 08:28:45 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Extending phpScheduleIt – Writing a Pre-Reservation Plugin  (Read 12099 times)
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 6409


WWW
« on: July 30, 2012, 01:25:51 PM »

I wrote a post walking through how to write a pre-reservation plugin. As always, your feedback in welcome!

http://php.brickhost.com/blog/?p=74
Logged
toconnell
Newbie
*

Karma: 0
Posts: 10


« Reply #1 on: June 07, 2013, 09:23:49 AM »

I think this will be perfect for what I want.. I figured out where to put it too!  Thanks..
I just am not sure how to connect to another database and validate based on two things - 1. the user first name and last name match the phpschedule it user first name and last name and 2.  If our database shows the users as ACTIVE or active=1. 

I have always done this with sort of a sql statement and call in the past where I needed to do something like this.  I am a very novice coder so I am a bit hesitant to just experiment away.  Your suggestions on the code for this validation script are welcome.  I am going to put something together based on your example script and post here for your review please.  Thanks, Tina
Logged
toconnell
Newbie
*

Karma: 0
Posts: 10


« Reply #2 on: June 07, 2013, 11:14:21 AM »

Ok.. here goes.. what do you think?

<?php
/**
Copyright 2012 Nick Korbel

This file is part of phpScheduleIt.

phpScheduleIt is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

phpScheduleIt is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with phpScheduleIt.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /* check_user is the routine where you create your own validation
   function.  This sample routine connects to a mysql database and
   queries on the username to access a plain-text password from the
   database.  If the user is found, the password is validated by
   simple string comparison.

   check_user should return 0 for invalid user, non-zero for valid user
*/


 //Connect to mysql database to validate user credentials - i.e. name match and the field ACTIVE=1 //

function check_user($user, $pass)
{
  $valid = 0;

  $link = mysql_connect("localhost", "DB USER NAME HERE", "DB PASSWORD HERE")
    or die("Unable to connect to mysql server");
  mysql_select_db("DB NAME HERE", $link)
    or die("Unable to select mysql database");

 /*Compare first name and last name of both databases to insure have proper user, then confirm for that user that the field Active =1*/

$username = $HTTP_POST_VARS["username"];
$query = mysql_query("select Name from compliance where Active = '1'");
if (strcmp($username) !="$Name")  {
if (strcmp($Active) !='1')  {
    echo("+VALID\n");
  }
  mysql_close($link);
  return $valid;
}

/* Since the username will be sent to MySQL, validate it against a
   regular expression.
   Only allow usernames that are letters, numbers, hyphens, underscores,
   and in general are just 1-32 characters in length
   You can change this check as needed.
*/
if (preg_match('/^([-_a-zA-Z0-9]{1,32})$/', $HTTP_POST_VARS["user"], $regs)) {
  $user = $regs[0];
} else {
  $user = "";
}

/*class PreReservationExampleValidation implements IReservationValidationService
{
   /**
    * @var IReservationValidationService
    */
   private $serviceToDecorate;

   public function __construct(IReservationValidationService $serviceToDecorate)
   {
      $this->serviceToDecorate = $serviceToDecorate;
   }

   /**
    * @param ReservationSeries|ExistingReservationSeries $series
    * @return IReservationValidationResult
    */
   public function Validate($series)
   {
      $result = $this->serviceToDecorate->Validate($series);

      // don't bother validating this rule if others have failed
      if (!$result->CanBeSaved())
      {
         return $result;
      }

      return $this->EvaluateCustomRule($series);
   }

   /**
    * @param ReservationSeries $series
    * @return bool
    */
   private function EvaluateCustomRule($series)
   {
      Log::Debug('Evaluating custom pre reservation rule');
      // make your custom checks here
      $configFile = Configuration::Instance()->File('PreReservationExample');
      $maxValue = $configFile->GetKey('custom.attribute.max.value');
      $customAttributeId = $configFile->GetKey('custom.attribute.id');

      $attributeValue = $series->GetAttributeValue($customAttributeId);

      $isValid = $attributeValue <= $maxValue;

      if ($isValid)
      {
         return new ReservationValidationResult();
      }

      return new ReservationValidationResult(false, "Value of custom attribute cannot be greater than $maxValue");
   }
}

?>
Logged
Alecardo
Jr. Member
**

Karma: 0
Posts: 81


« Reply #3 on: June 07, 2013, 04:00:18 PM »

What is this supposed to do?
Logged
percane
Hero Member
*****

Karma: 4
Posts: 895


« Reply #4 on: June 10, 2013, 09:42:11 AM »

it's checking her user table in a different database to confirm a login
Logged
Alecardo
Jr. Member
**

Karma: 0
Posts: 81


« Reply #5 on: June 11, 2013, 12:24:26 AM »

Cool, Thanks
Logged
seencarter
Newbie
*

Karma: 0
Posts: 7


WWW
« Reply #6 on: July 05, 2013, 04:15:08 AM »

Ok.. here goes.. what do you think?

<?php
/**
Copyright 2012 Nick Korbel

It was great!!
____________________________________________
« Last Edit: August 23, 2013, 12:43:13 AM by seencarter » Logged
nickbarel
Newbie
*

Karma: 0
Posts: 3


« Reply #7 on: July 05, 2013, 04:32:53 AM »

It awsome. Thank you very much
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2006-2007, Simple Machines Valid XHTML 1.0! Valid CSS!