| 
<?php
 /**
 * @author Prakash Khanchandani
 * @copyright 2013
 * @program user.php
 * @description user maintenance
 * @specialities    - rearrange column order in form
 *                     - mix of explicit auto validations and programmatic validations
 */
 
 
 session_start();
 require_once ("classes.php");
 
 
 function createTableObject()
 {
 $obj = new userTable;
 if ($obj->getListAndColumns() === false)
 return false;
 else
 return $obj;
 }
 
 
 #
 #
 #
 #
 #
 
 
 class userTable extends mstrTable
 {
 function getListAndColumns()
 {
 $this->tableName = 'users';
 $this->ignoreInForm = array('passWrd');
 /*
 create foreign references for bank, branch, and group. */
 $this->explicitFrgnRef[] = array("bnkPrmtrs", "bank = parentBank");
 $this->explicitFrgnRef[] = array("brnchPrmtrs", "bank=parentBank",
 "branch=parentBranch");
 
 return parent::getListAndColumns('userId', 'userName', 'parentBank',
 'parentBranch');
 }
 
 
 function populateRecordValues()
 {
 if (parent::populateRecordValues() === false)
 return false;
 /*
 populate the adtnlInfo with bankName and branchName. We have given explicit
 foreign references and therefore the reference records would be available in
 the master class. */
 $bankDes = $this->getForeignRefDescription('bnkPrmtrs', 'bankName');
 $branchDes = $this->getForeignRefDescription('brnchPrmtrs', 'branchName');
 $grpDes = $this->getForeignRefDescription('groups', 'grpDes');
 
 $idBank = $this->getColDefsId('parentBank');
 $idBranch = $this->getColDefsId('parentBranch');
 $idGrp = $this->getColDefsId('grp');
 
 $this->addAdditionalInfo($idBank, $bankDes);
 $this->addAdditionalInfo($idBranch, $branchDes);
 $this->addAdditionalInfo($idGrp, $grpDes);
 
 return true;
 }
 
 
 protected function validateInput()
 {
 /* Since we have given explicit foreign references for bank and branch, and there is
 an implicit foreign reference for the group, we need not do those checks here. But
 there are a lot of other checks that have to be done manually through this function. */
 
 /*
 get various fields entered by user - they are required throughout this func. If you
 cant get it, no point in continuing. */
 $userId = $this->getColDefsVal("userId");
 $parentBank = $this->getColDefsVal("parentBank");
 $parentBranch = $this->getColDefsVal("parentBranch");
 $userType = $this->getColDefsVal("userType");
 $isCashTell = $this->getColDefsVal("isCashTell");
 $isHC = $this->getColDefsVal("isHC");
 
 if ($userId === false or $userType === false or $isCashTell === false or $isHC
 === false) {
 addToErrorMsg('could not get one of the fields entered');
 return false;
 }
 $errors = 0;
 /*
 there can be only one user with userType SDBA. Check if there are any others
 present. If the current user already has a record, you might be counting him as
 well, so ignore him for the search. Note that since userType is defined as an
 enum column, the basic checks would have been done already; you dont have to
 check that it is SDBA, DBA, NORM, etc. */
 if ($userType == 'SDBA') {
 $qry = "select count(*)
 from users where
 parentBank = '$parentBank' and
 userId <> '$userId' and
 userType = 'SDBA'
 ";
 $script = new mstrScripts;
 $result = $script->runCountQry($qry);
 if ($result === false) {
 addToErrorMsg($script->getErrorMsg());
 $errors = $errors + 1;
 } else {
 if ($result > 0) {
 addToErrorMsg('SDBA user already available for this bank');
 $errors = $errors + 1;
 }
 }
 }
 /*
 check the count of input $type - Vault or Headcashier. There can be only
 one per bank/branch which is also input. Dont include this userId in the
 count */
 if ($isCashTell == 'V') {
 $qry = "select count(*)
 from users where
 parentBank = '$parentBank' and
 parentBranch = '$parentBranch' and
 userId <> '$userId' and
 isCashTell = 'V'
 ";
 $script = new mstrScripts;
 $result = $script->runCountQry($qry);
 if ($result === false) {
 addToErrorMsg($script->getErrorMsg());
 $errors = $errors + 1;
 } else {
 if ($result > 0) {
 addToErrorMsg('Vault user already available for this branch');
 $errors = $errors + 1;
 }
 }
 }
 /*
 similarly, there can be only one headCashier per branch. */
 if ($isHC == 'Y') {
 $qry = "select count(*)
 from users where
 parentBank = '$parentBank' and
 parentBranch = '$parentBranch' and
 userId <> '$userId' and
 isHC = 'Y'
 ";
 $script = new mstrScripts;
 $result = $script->runCountQry($qry);
 if ($result === false) {
 addToErrorMsg($script->getErrorMsg());
 $errors = $errors + 1;
 } else {
 if ($result > 0) {
 addToErrorMsg('Head Cashier already available for this branch');
 $errors = $errors + 1;
 }
 }
 }
 
 
 if ($errors > 0)
 return false;
 
 return true;
 }
 }
 
 
 #
 #
 #
 #
 #
 
 
 if (!isset($_REQUEST['actn'])) {
 $obj = createTableObject();
 } else {
 /* if the user has taken some action, handle it. */
 $obj = handleRequestOption();
 }
 
 
 $form = new mstrFH($obj);
 $form->setDemoNotes(userNotes());
 $form->clmnOrdr = array("userId", "userName", "parentBank", "parentBranch",
 "autoAuthorise", "selfAuthorise");
 $form->displayForm();
 ?>
 |