コード例 #1
0
ファイル: ActivityReport.php プロジェクト: phpsmith/IS4C
 public function preprocess()
 {
     global $FANNIE_OP_DB, $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS;
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         $this->errors[] = "The Coop Cred plugin is not enabled.";
         return False;
     }
     if (array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) && $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] != "") {
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     } else {
         $this->errors[] = "The Coop Cred database is not assigned in the " . "Coop Cred plugin configuration.";
         return False;
     }
     $this->cardNo = (int) FormLib::get('memNum', 0);
     $this->programID = (int) FormLib::get('programID', 0);
     $ccpModel = new CCredProgramsModel($dbc);
     $ccpModel->programID($this->programID);
     $prog = array_pop($ccpModel->find());
     if ($prog != null) {
         $this->programName = $prog->programName();
         $this->programBankID = $prog->bankID();
     } else {
         $this->errors[] = "Error: Program ID {$this->programID} is not known.";
         return False;
     }
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $cdModel = new CustdataModel($dbc);
     $cdModel->CardNo($this->cardNo);
     $cdModel->personNum(1);
     $mem = array_pop($cdModel->find());
     if ($mem != null) {
         $this->memberFullName = $mem->FirstName() . " " . $mem->LastName();
     } else {
         $noop = 1;
         $this->errors[] = "Error: Member {$this->cardNo} is not known.";
         return False;
     }
     /* 25Mar2015 Under bootstrap the non-sortable format doesn't really work.
      */
     $this->sortable = True;
     return parent::preprocess();
 }
コード例 #2
0
 private function ajax_save_program()
 {
     global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     $OP = $FANNIE_OP_DB . $dbc->sep();
     /* Place to accumulate not-immediately-fatal messages
      *  that will be displayed in the ajax-return-string.
      */
     $returnMessage = "";
     /* These are from the query (parameters) string in the AJAX request
      *  and are the same as the input form id= values.
      */
     $progno = FormLib::get_form_value('progno', 0);
     $progname = FormLib::get_form_value('progname', '');
     $isactive = FormLib::get_form_value('isactive', 0);
     $startdate = FormLib::get_form_value('startdate', '');
     $enddate = FormLib::get_form_value('enddate', '');
     if ($enddate == 'NULL' || $enddate == '0000-00-00') {
         $enddate = '';
     }
     $tendertype = FormLib::get_form_value('tendertype', '');
     $tendername = FormLib::get_form_value('tendername', '');
     $tenderkeycap = FormLib::get_form_value('tenderkeycap', '');
     $inputtender = FormLib::get_form_value('inputtender', '');
     $paymentid = FormLib::get_form_value('paymentid', 0);
     $paymentname = FormLib::get_form_value('paymentname', '');
     $paymentkeycap = FormLib::get_form_value('paymentkeycap', '');
     $bankid = FormLib::get_form_value('bankid', 0);
     $creditok = FormLib::get_form_value('creditok', 0);
     $maxcredit = FormLib::get_form_value('maxcredit', 0);
     $inputok = FormLib::get_form_value('inputok', 0);
     $transferok = FormLib::get_form_value('transferok', 0);
     $origTender = FormLib::get_form_value('origtender', '');
     $origDepartment = FormLib::get_form_value('origdepartment', 0);
     $isnew = FormLib::get_form_value('isnew', 9);
     /* 
      * Check for problems, conflicts mostly:
      */
     $sMessage = "";
     /* Each check */
     /* Tender */
     $sErrors = array();
     $sargs = array();
     $sq = "SELECT tenderType, programName\n            FROM CCredPrograms \n            WHERE tenderType = ? ";
     $sargs[] = $tendertype;
     if (!$isnew) {
         $sq .= "AND programID != ?";
         $sargs[] = $progno;
     }
     $ss = $dbc->prepare($sq);
     $sr = $dbc->execute($ss, $sargs);
     while ($srow = $dbc->fetch_row($sr)) {
         $sErrors[] = $srow['programName'];
     }
     if (count($sErrors) > 0) {
         $sMessage .= sprintf("\nThe Tender %s is already in use by:\n", $tendertype);
         $sMessage .= implode("\n", $sErrors);
         $sMessage .= "\nPlease choose a different one." . "\nIf the one you need doesn't exist yet,\n" . " set it up in the Tenders Editor\n" . " and then edit this Program again." . "\nAlso see the Tender '?' Help." . "";
     }
     /* Payment Department */
     $sErrors = array();
     $sargs = array();
     $sq = "SELECT paymentDepartment, paymentName, programName\n            FROM CCredPrograms \n            WHERE paymentDepartment = ? ";
     $sargs[] = $paymentid;
     if (!$isnew) {
         $sq .= "AND programID != ?";
         $sargs[] = $progno;
     }
     $ss = $dbc->prepare($sq);
     $sr = $dbc->execute($ss, $sargs);
     while ($srow = $dbc->fetch_row($sr)) {
         $sErrors[] = $srow['programName'];
     }
     if (count($sErrors) > 0) {
         $sMessage .= sprintf("\nThe Department %s is already in use by:\n", $paymentid);
         $sMessage .= implode("\n", $sErrors);
         $sMessage .= "\nPlease choose a different one." . "\nIf the one you need doesn't exist yet,\n" . " set it up in the Departments Editor\n" . " and then edit this Program again." . "\nAlso see the Department '?' Help." . "";
     }
     /* Banker Department */
     $sErrors = array();
     $sargs = array();
     $sq = "SELECT bankID, programName\n            FROM CCredPrograms \n            WHERE bankID = ? ";
     $sargs[] = $bankid;
     if (!$isnew) {
         $sq .= "AND programID != ?";
         $sargs[] = $progno;
     }
     $ss = $dbc->prepare($sq);
     $sr = $dbc->execute($ss, $sargs);
     while ($srow = $dbc->fetch_row($sr)) {
         $sErrors[] = $srow['programName'];
     }
     if (count($sErrors) > 0) {
         $sMessage .= sprintf("\nThe Banker %s is already in use by:\n", $bankid);
         $sMessage .= implode("\n", $sErrors);
         $sMessage .= "\nPlease choose a different one." . "\nIf the one you need doesn't exist yet,\n" . " set it up in the Members Editor\n" . " and then edit this Program again." . "\nAlso see the Banker '?' Help." . "";
     }
     /* After all checks done.
      */
     if ($sMessage) {
         $sMessage = preg_replace("/^\n+/", "", $sMessage);
         $sMessage .= "\n\nNo current changes have been Saved.";
         echo $sMessage;
         return;
     }
     /* Save changes to or Create the Program proper.
      */
     $model = new CCredProgramsModel($dbc);
     $model->programID($progno);
     $model->programName($progname);
     /* Cannot be active if any dummy's in use. */
     $resetIsactive = False;
     if ($isactive == 1 && ($paymentid == $this->dummyDepartment || $tendertype == "{$this->dummyTenderCode}" || $bankid == $this->dummyBanker)) {
         $resetIsactive = True;
         $isactive = 0;
     }
     $model->active($isactive);
     $model->startDate($startdate);
     $model->endDate($enddate);
     $model->tenderType($tendertype);
     $model->tenderName($tendername);
     $model->tenderKeyCap($tenderkeycap);
     $model->inputTenderType($inputtender);
     $model->paymentDepartment($paymentid);
     $model->paymentName($paymentname);
     $model->paymentKeyCap($paymentkeycap);
     $model->bankID($bankid);
     $model->creditOK($creditok);
     $model->maxCreditBalance($maxcredit);
     $model->inputOK($inputok);
     $model->transferOK($transferok);
     $model->modified(date('Y-m-d H:i:s'));
     $model->modifiedBy($this->authUserNumber);
     /* save() decides UPDATE vs INSERT based on whether programID already
      *  exists.
      */
     $saved = $model->save();
     if ($isnew == 1) {
         if ($saved === False) {
             echo 'Error: could not create Program';
             return;
         }
         /* Get the programID that was assigned by auto-increment.
          */
         $newQ = "SELECT LAST_INSERT_ID()";
         $rslt = $dbc->query("{$newQ}");
         if ($rslt === False) {
             $msg = sprintf("Failed: %s", $dbc->error());
             echo $msg;
             return;
         }
         $rows = $dbc->num_rows($rslt);
         if ($rows > 0) {
             $row = $dbc->fetch_row($rslt);
             $retVal = $row[0];
         } else {
             $retVal = 0;
         }
         if ($retVal == 0) {
             $msg = "Failed to return new Program id.";
             echo $msg;
             return;
         }
         $progno = $retVal;
         $returnMessage .= sprintf("\nCreated Program %s (#%d)", $progname, $progno);
         /* If there are no dummies, re-create the views.
          */
         if ($paymentid != $this->dummyDepartment && $tendertype != "{$this->dummyTenderCode}" && $bankid != $this->dummyBanker) {
             $rslt = $this->updateViews($dbc);
             if ($rslt !== True) {
                 if (stripos($rslt, "fatal") !== False) {
                     echo $returnMessage . "\n{$rslt}";
                     return;
                 } else {
                     $returnMessage .= "\n{$rslt}";
                 }
             }
         }
     } else {
         if ($saved === False) {
             echo 'Error: could not save the changes to the Program';
             return;
         } else {
             $returnMessage .= sprintf("\nSaved Program %s (#%d)", $progname, $progno);
         }
         /* During testing pTLCC writes string error messages to Fannie log.
          * All problems are noted in return value.
          */
         $laneTest = $model->pushToLanesCoopCred();
         if ($laneTest === true) {
             $returnMessage .= "\nUpdated lanes.";
         } else {
             if (is_string($laneTest)) {
                 $returnMessage .= sprintf("\nError saving Program %s (#%d) to lanes: %s", $progname, $progno, $laneTest);
             } else {
                 $returnMessage .= sprintf("\nError saving Program %s (#%d) to lanes.", $progname, $progno);
             }
         }
     }
     /* Membership of Banker in Program
      * Create new membership or change Banker to this Program.
      * Check first that Banker has only one membership,
      *  that something has not gone wrong.
      */
     if ($bankid == $this->dummyBanker) {
         $returnMessage .= "\nThe Program may not be actually used until " . "a real Banker is assigned.";
     } else {
         $ccmModel = new CCredMembershipsModel($dbc);
         $ccmModel->cardNo($bankid);
         /* Default values for new programs.
          * Should these be configurable? Probably.
          */
         $mCreditBalance = 0.0;
         $mCreditLimit = 0.0;
         $mMaxCreditBalance = 0.0;
         $mCreditOK = 1;
         $mInputOK = 1;
         $mTransferOK = 1;
         //
         $found = 0;
         $memships = array();
         foreach ($ccmModel->find() as $obj) {
             $found++;
             $memships[] = $obj->programID(-1);
             /* Keep the values of an existing membership.
              * If it changes Programs.
              * Really a good idea?
              * If they, esp creditBalance, are not 0 catastrophe may ensue!
              */
             $mCreditBalance = $obj->creditBalance();
             $mCreditLimit = $obj->creditLimit();
             $mMaxCreditBalance = $obj->maxCreditBalance();
             $mCreditOK = $obj->creditOK();
             $mInputOK = $obj->inputOK();
             $mTransferOK = $obj->transferOK();
         }
         if ($found > 1) {
             $msg = "Banker %d is already associated with more than one " . "(in fact %d) Program: %s" . "\nPlease use a different one.";
             echo $returnMessage . sprintf("\n{$msg}", $bankid, $found, implode(', ', $memships));
             return;
         }
         $ccmModel = new CCredMembershipsModel($dbc);
         $ccmModel->cardNo($bankid);
         $ccmModel->programID($progno);
         $ccmModel->creditBalance($mCreditBalance);
         $ccmModel->creditLimit($mCreditLimit);
         $ccmModel->maxCreditBalance($mMaxCreditBalance);
         $ccmModel->creditOK($mCreditOK);
         $ccmModel->inputOK($mInputOK);
         $ccmModel->transferOK($mCreditOK);
         $ccmModel->isBank(1);
         $ccmModel->modified(date('Y-m-d H:i:s'));
         $ccmModel->modifiedBy($this->authUserNumber);
         $membershipSaved = $ccmModel->save();
         if ($membershipSaved === False) {
             $msg = "Adding or updating membership in Program %d for Banker %d failed.";
             echo $returnMessage . sprintf("\n{$msg}", $progno, $bankid);
             return;
         }
         /* Membership of Banker in Program
          * Create new membership or change Banker to this Program.
          * Check first that Banker has only one membership,
          *  that something has not gone wrong.
          */
         $ccmModel = new CCredMembershipsModel($dbc);
         $ccmModel->cardNo($bankid);
         /* There should be one or none.
          * find() returns an array, possibly empty, so foreach is needed.
          */
         /* Default values for new programs.
          * Should these be configurable? Probably.
          */
         $mCreditBalance = 0.0;
         $mCreditLimit = 0.0;
         $mMaxCreditBalance = 0.0;
         $mCreditOK = 1;
         $mInputOK = 1;
         $mTransferOK = 1;
         //
         $found = 0;
         $memships = array();
         foreach ($ccmModel->find() as $obj) {
             $found++;
             $memships[] = $obj->programID(-1);
             /* Keep the values of an existing membership.
              * If it changes Programs.
              * Really a good idea? If they are not 0 catastrophe may ensue!
              */
             $mProgramID = $obj->programID();
             $mCreditBalance = $obj->creditBalance();
             $mCreditLimit = $obj->creditLimit();
             $mMaxCreditBalance = $obj->maxCreditBalance();
             $mCreditOK = $obj->creditOK();
             $mInputOK = $obj->inputOK();
             $mTransferOK = $obj->transferOK();
         }
         if ($found > 1) {
             $msg = "Banker %d already has more than one (in fact %d) memberships: %s";
             echo $returnMessage . sprintf("\n{$msg}", $bankid, $found, implode(', ', $memships));
             return;
         }
         $ccmModel = new CCredMembershipsModel($dbc);
         $ccmModel->cardNo($bankid);
         $ccmModel->programID($progno);
         $ccmModel->creditBalance($mCreditBalance);
         $ccmModel->creditLimit($mCreditLimit);
         $ccmModel->maxCreditBalance($mMaxCreditBalance);
         $ccmModel->creditOK($mCreditOK);
         $ccmModel->inputOK($mInputOK);
         $ccmModel->transferOK($mCreditOK);
         $ccmModel->isBank(1);
         $ccmModel->modified(date('Y-m-d H:i:s'));
         $ccmModel->modifiedBy($this->authUserNumber);
         $membershipSaved = $ccmModel->save();
         if ($membershipSaved === False) {
             $msg = "Adding or updating membership in Program %d for Banker %d failed.";
             $returnMessage .= sprintf("\n{$msg}", $progno, $bankid);
         }
         // not dummyBanker
     }
     /* #'u Updates to Fannie tables
      */
     if ($tendertype == $this->dummyTenderCode) {
         $returnMessage .= "\nThe Program may not be actually used until " . "a real Tender is assigned.";
     } else {
         if ($tendername != "") {
             $opQ = "UPDATE {$OP}tenders\n                    SET TenderName = ?\n                    WHERE TenderCode = ?";
             $opArgs = array();
             $opArgs[] = $tendername;
             $opArgs[] = $tendertype;
             $opS = $dbc->prepare($opQ);
             $opR = $dbc->execute($opS, $opArgs);
             if ($opR === False) {
                 $returnMessage .= "\nSaved changes to the Program proper but updating the " . "Tender name in CORE Backend failed.";
             }
         }
     }
     if ($paymentid == $this->dummyDepartment) {
         $returnMessage .= "\nThe Program may not be actually used until " . "a real Input/Payment is assigned.";
     } else {
         if ($paymentname != "") {
             $opQ = "UPDATE {$OP}departments\n                    SET dept_name = ?\n                    WHERE dept_no = ?";
             $opArgs = array();
             $opArgs[] = $paymentname;
             $opArgs[] = $paymentid;
             $opS = $dbc->prepare($opQ);
             $opR = $dbc->execute($opS, $opArgs);
             if ($opR === False) {
                 $returnMessage .= "\nSaved changes to the Program proper but updating the " . "Department name in CORE Backend failed.";
             }
         }
     }
     /* Update views if Department or Tender have changed and
      *  as long as neither is dummy.
      */
     if ($paymentid != $origDepartment || $tendertype != $origTender) {
         if ($paymentid != $this->dummyDepartment && $tendertype != "{$this->dummyTenderCode}" && $bankid != $this->dummyBanker) {
             $rslt = $this->updateViews($dbc);
             if ($rslt !== True) {
                 if (stripos($rslt, "fatal") !== False) {
                     echo $returnMessage . "\n{$rslt}";
                     return;
                 } else {
                     $returnMessage .= "\n{$rslt}";
                 }
             } else {
                 $returnMessage .= "\nUpdated views.";
             }
         }
     }
     if ($resetIsactive) {
         $returnMessage .= "\nThe Program has been marked Not-Active because " . "one or more dummy values are in use.";
     }
     $returnMessage = preg_replace("/^\n+/", "", $returnMessage);
     echo $returnMessage;
     // ajax_save_program()
 }
コード例 #3
0
 function preprocess()
 {
     global $FANNIE_CORRECTION_CASHIER, $FANNIE_CORRECTION_LANE, $FANNIE_CORRECTION_DEPT;
     global $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB;
     if (isset($FANNIE_CORRECTION_CASHIER)) {
         $this->CORRECTION_CASHIER = $FANNIE_CORRECTION_CASHIER;
     }
     if (isset($FANNIE_CORRECTION_LANE)) {
         $this->CORRECTION_LANE = $FANNIE_CORRECTION_LANE;
     }
     if (isset($FANNIE_CORRECTION_DEPT)) {
         $this->CORRECTION_DEPT = $FANNIE_CORRECTION_DEPT;
     }
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         $this->errors .= "Error: Coop Cred Plugin is not enabled.";
         return True;
     }
     if (array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) && $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] != "") {
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     } else {
         $this->errors .= "Error: Coop Cred Database not named in Plugin Settings.";
         return True;
     }
     $OP = $FANNIE_OP_DB . $dbc->sep();
     if (FormLib::get_form_value('programID', False) !== False) {
         $this->programID = FormLib::get_form_value('programID');
     } else {
         $this->errors .= "<em>" . _("Error: ") . _("Program ID not supplied.") . "</em>" . "";
         return True;
     }
     if (FormLib::get_form_value('programID') == "0") {
         $backLabel = _("Return to Member Editor");
         $this->errors .= "<em>" . _("Warning: ") . _("The Member does not yet belong to a Program.") . "<br />" . _("Please add him/her to a Program, Save, and Edit again to do the Transfer.") . "</em>" . "<br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>" . "";
         return True;
     }
     $ccpModel = new CCredProgramsModel($dbc);
     $ccpModel->programID($this->programID);
     $inputOK = null;
     $prog = array_pop($ccpModel->find());
     if ($prog == null) {
         $this->errors .= "<em>Error: Program ID {$this->programID} is not known.</em>";
         return True;
     }
     $inputOK = $prog->inputOK();
     $this->programPaymentDepartment = $prog->paymentDepartment();
     $this->dept = $prog->paymentDepartment();
     $this->programName = $prog->programName();
     $this->programBankNumber = $prog->bankID();
     /* To use while choosing dept is still part of the form.
      * It isn't, in Input or Transfer but maybe in another Tool?
      */
     $this->depts[$this->dept] = $this->programName;
     /* 16Dec2014 This is not tickable on the form yet.
      */
     $this->negativeBalanceOK = FormLib::get_form_value('negativeBalanceOK', False);
     foreach ($_REQUEST as $name => $value) {
         $item = "{$name}={$value}";
         if (!in_array("{$item}", $this->hiddenSearch) && substr($name, 0, 6) != "submit") {
             $this->hiddenSearch[] = "{$item}";
         }
     }
     if (FormLib::get_form_value('memEDIT', False) !== False) {
         $this->memberBeingEdited = FormLib::get_form_value('memEDIT');
     }
     if (FormLib::get_form_value('submit1', False) !== False) {
         $this->mode = 'confirm';
     } elseif (FormLib::get_form_value('submit2', False) !== False) {
         $this->mode = 'finish';
     }
     /* If the transfer values form is to be displayed
      */
     if ($this->mode == 'init') {
         $memNum = FormLib::get_form_value('memIN');
         if ($memNum != 0) {
             $q = $dbc->prepare_statement("SELECT FirstName,LastName\n                    FROM {$OP}custdata\n                    WHERE CardNo=? AND personNum=1");
             $r = $dbc->exec_statement($q, array($memNum));
             if ($dbc->num_rows($r) == 0) {
                 $this->errors .= "<em>Error: no such member: " . $memNum . "</em>" . "<br /><br />" . "<a href=\"\" onclick=\"back(); return false;\">Back</a>";
                 return True;
             }
             $row = $dbc->fetch_row($r);
             $this->name1 = $row['FirstName'] . ' ' . $row['LastName'];
         }
     }
     /* error check of inputs from form
      */
     if ($this->mode != 'init') {
         $this->dept = FormLib::get_form_value('dept');
         $this->amount = FormLib::get_form_value('amount');
         $this->cn1 = FormLib::get_form_value('memFrom');
         $this->cn2 = FormLib::get_form_value('memTo');
         $this->comment = FormLib::get_form_value('comment');
         /* If full URL is used to go back to the Transfer form
          * compose the search string so the parts op filled out aren't lost.
          * I don't know that this was ever used or worked.
          */
         foreach ($_REQUEST as $name => $value) {
             if (substr($name, 0, 6) != "submit") {
                 $item = "{$name}={$value}";
                 if (!in_array("{$item}", $this->hiddenSearch)) {
                     $this->hiddenSearch[] = "{$item}";
                 }
             }
         }
         $this->hiddenSearchString = "?" . implode('&amp;', $this->hiddenSearch);
         /* This "back" technique allows the form to display but loses any
          *  input values.
          * Not all of these errors are actually possible as the form now is.
          */
         $backLabel = _("Return to Transfer form");
         if (!isset($this->depts[$this->dept])) {
             $this->errors .= "<em>Error: Payment department doesn't exist</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ("{$this->amount}" == "") {
             $this->errors .= "<em>Error: please enter an amount to transfer</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->amount < 0) {
             $this->errors .= "<em>Error: amount to transfer given (" . $this->amount . ") is negative.</em>" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if (!is_numeric($this->amount)) {
             $this->errors .= "<em>Error: amount to transfer given (" . $this->amount . ") isn't a number</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if (!is_numeric($this->cn1)) {
             $this->errors .= "<em>Error: transfer 'From' member given (" . $this->cn1 . ") isn't a number</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn1 == 0) {
             $this->errors .= "<em>Error: choose a  member to transfer 'From'</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if (!is_numeric($this->cn2)) {
             $this->errors .= "<em>Error: transfer 'To' member given (" . $this->cn2 . ") isn't a number</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn1 == $this->cn2) {
             $this->errors .= "<em>Error: 'From' and 'To' cannot be the same</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn2 == 0) {
             $this->errors .= "<em>Error: choose a member to tranfser 'To'</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn1 > 0) {
             $q = "SELECT c.FirstName, c.LastName, b.availableBalance\n                    FROM {$OP}custdata c\n                    JOIN CCredMemCreditBalance b ON c.CardNo = b.cardNo\n                    WHERE c.CardNo=? AND c.personNum=1\n                    AND b.programID =" . $this->programID . "";
             $s = $dbc->prepare_statement($q);
             $r = $dbc->exec_statement($s, array($this->cn1));
             if ($dbc->num_rows($r) == 0) {
                 $this->errors .= "<em>Error: no such member: " . $this->cn1 . "</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
                 return True;
             }
             $row = $dbc->fetch_row($r);
             $this->name1 = $row['FirstName'] . ' ' . $row['LastName'];
         } else {
             $this->name1 = "Account Adjustment";
         }
         if ($this->mode == 'confirm' && $this->name1 != 'Account Adjustment' && $this->negativeBalanceOK == False && $row['availableBalance'] < $this->amount) {
             $this->errors .= "<em>Error: you may not transfer more: \$" . $this->amount . " than the Available Balance in the account: \$" . $row['availableBalance'] . "</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         $q = $dbc->prepare_statement("SELECT FirstName,LastName\n                FROM {$OP}custdata\n                WHERE CardNo=? AND personNum=1");
         $r = $dbc->exec_statement($q, array($this->cn2));
         if ($dbc->num_rows($r) == 0) {
             $this->errors .= "<em>Error: no such member: " . $this->cn2 . "</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         $row = $dbc->fetch_row($r);
         $this->name2 = $row['FirstName'] . ' ' . $row['LastName'];
     }
     return True;
     // preprocess()
 }
コード例 #4
0
ファイル: ProgramEventsReport.php プロジェクト: phpsmith/IS4C
 function preprocess()
 {
     global $FANNIE_ROOT, $FANNIE_URL, $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS;
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         $this->errors[] = "The Coop Cred plugin is not enabled.";
         return True;
     }
     if (array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) && $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] != "") {
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     } else {
         $this->errors[] = "The Coop Cred database is not assigned in the " . "Coop Cred plugin configuration.";
         return True;
     }
     $config = new CCredConfigModel($dbc);
     $config->configID(1);
     $loadOK = $config->load();
     if (!$loadOK) {
         $msg = "Problem: Please 'Configure Coop Cred' from the Coop Cred Admin menu.";
         $this->errors[] = $msg;
         return True;
     } else {
         $this->bankerMin = $config->bankerMin();
         $this->bankerMax = $config->bankerMax();
     }
     /**
       Whether invoked by form submission.
     */
     if (isset($_REQUEST['programID'])) {
         // Better to do this in JS in the form.
         if ($_REQUEST['programID'] == "") {
             $this->errors[] = "Please choose a Program";
             $this->add_script("{$FANNIE_URL}src/CalendarControl.js");
             return True;
         }
         $programID = (int) $_REQUEST['programID'];
         $ccpModel = new CCredProgramsModel($dbc);
         $ccpModel->programID($programID);
         $prog = array_pop($ccpModel->find());
         if ($prog != null) {
             $this->programID = $prog->programID();
             $this->programName = $prog->programName();
             $this->programBankID = $prog->bankID();
             //obs. $this->bankID = $prog->bankID();
             $this->paymentDepartment = $prog->paymentDepartment();
             $this->programStartDate = preg_match("/^[12]\\d{3}-\\d{2}-\\d{2}/", $prog->startDate()) ? $prog->startDate() : '1970-01-01';
         } else {
             $this->errors[] = "Error: Program ID {$programID} is not known.";
             return True;
         }
         if (!FormLib::get_form_value('sortable', False)) {
             $this->sortable = False;
             $this->report_headers = array('When', 'Member#', 'Member Name', 'Event', '$ Amount', 'Comment');
         } else {
             $this->report_headers = array('Date', 'When', 'Member#', 'Member Name', 'Event', '$ Amount', 'Comment');
         }
         $this->content_function = "report_content";
         if (isset($_REQUEST['excel']) && $_REQUEST['excel'] == 'xls') {
             $this->report_format = 'xls';
             $this->has_menus(False);
         } elseif (isset($_REQUEST['excel']) && $_REQUEST['excel'] == 'csv') {
             $this->report_format = 'csv';
             $this->has_menus(False);
         }
     } else {
         if (FormLib::get_form_value('pid', 0) != 0) {
             $this->pid = FormLib::get_form_value('pid', 0);
         }
         $this->add_script("{$FANNIE_URL}src/CalendarControl.js");
     }
     return True;
     // preprocess()
 }
コード例 #5
0
ファイル: CoopCredInputTool.php プロジェクト: phpsmith/IS4C
 function preprocess()
 {
     global $FANNIE_CORRECTION_CASHIER, $FANNIE_CORRECTION_LANE, $FANNIE_CORRECTION_DEPT;
     global $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB;
     if (isset($FANNIE_CORRECTION_CASHIER)) {
         $this->CORRECTION_CASHIER = $FANNIE_CORRECTION_CASHIER;
     }
     if (isset($FANNIE_CORRECTION_LANE)) {
         $this->CORRECTION_LANE = $FANNIE_CORRECTION_LANE;
     }
     if (isset($FANNIE_CORRECTION_DEPT)) {
         $this->CORRECTION_DEPT = $FANNIE_CORRECTION_DEPT;
     }
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         $this->errors .= _("Error: The Coop Cred Plugin is not enabled.");
         return True;
     }
     if (array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) && $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] != "") {
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     } else {
         $this->errors .= _("Error: Coop Cred Database not named in Plugin Settings.");
         return True;
     }
     if (FormLib::get_form_value('programID', False) !== False) {
         $this->programID = FormLib::get_form_value('programID');
     } else {
         $this->errors .= "<em>" . _("Error: ") . _("Program ID not supplied.") . "</em>" . "";
         return True;
     }
     if (FormLib::get_form_value('programID') == "0") {
         $backLabel = _("Return to Member Editor");
         $this->errors .= "<em>" . _("Warning: ") . _("The Member does not yet belong to a Program.") . "<br />" . _("Please add him/her to a Program, Save, and Edit again to do the Transfer.") . "</em>" . "<br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>" . "";
         return True;
     }
     $ccpModel = new CCredProgramsModel($dbc);
     $ccpModel->programID($this->programID);
     $inputOK = null;
     $prog = array_pop($ccpModel->find());
     if ($prog == null) {
         $this->errors .= "<em>Error: Program ID {$this->programID} is not known.</em>";
         return True;
     }
     $inputOK = $prog->inputOK();
     $this->programPaymentDepartment = $prog->paymentDepartment();
     $this->dept = $prog->paymentDepartment();
     $this->programName = $prog->programName();
     $this->inputTenderType = $prog->inputTenderType();
     $this->depts[$this->dept] = $this->programName;
     if (FormLib::get_form_value('memEDIT', False) !== False) {
         $this->memberBeingEdited = FormLib::get_form_value('memEDIT');
     }
     if (FormLib::get_form_value('submit1', False) !== False) {
         $this->mode = 'confirm';
     } elseif (FormLib::get_form_value('submit2', False) !== False) {
         $this->mode = 'finish';
     }
     if ($this->mode == 'init') {
         $memNum = FormLib::get_form_value('memIN');
         if ($memNum != 0) {
             $q = $dbc->prepare_statement("SELECT FirstName,LastName\n                    FROM {$FANNIE_OP_DB}{$dbc->sep()}custdata\n                    WHERE CardNo=? AND personNum=1");
             $r = $dbc->exec_statement($q, array($memNum));
             if ($dbc->num_rows($r) == 0) {
                 $this->errors .= "<em>Error: no such member: " . $memNum . "</em>" . "<br /><br />" . "<a href=\"\" onclick=\"back(); return false;\">Back</a>";
                 return True;
             }
             $row = $dbc->fetch_row($r);
             $this->name1 = $row['FirstName'] . ' ' . $row['LastName'];
         }
     }
     // error check inputs
     if ($this->mode != 'init') {
         $this->dept = FormLib::get_form_value('dept');
         $this->amount = FormLib::get_form_value('amount');
         $this->cn1 = FormLib::get_form_value('memFrom');
         $this->cn2 = FormLib::get_form_value('memTo');
         $this->comment = FormLib::get_form_value('comment');
         /* This "back" technique allows the form to display but loses any
          *  input values it had.
          */
         $backLabel = "Return to Input form";
         if (!isset($this->depts[$this->dept])) {
             $this->errors .= "<em>Error: Payment department doesn't exist</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ("{$this->amount}" == "") {
             $this->errors .= "<em>Error: please enter an amount to input</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->amount < 0) {
             $this->errors .= "<em>Error: amount to input given (" . $this->amount . ") is negative.</em>" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if (!is_numeric($this->amount)) {
             $this->errors .= "<em>Error: amount to input given (" . $this->amount . ") isn't a number</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if (!is_numeric($this->cn1)) {
             $this->errors .= "<em>Error: input 'From' member given (" . $this->cn1 . ") isn't a number</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         /* Since op. doesn't choose this in this Tool no need to check value.
            if ($this->cn1 == 0) {
                $this->errors .= "<em>Error: choose a  member to input 'From'</em>"
                    ."<br /><br />"
                    ."<a href=\"javascript:history.back();\">{$backLabel}</a>";
                return True;
            }
             */
         if (!is_numeric($this->cn2)) {
             $this->errors .= "<em>Error: input 'To' member given (" . $this->cn2 . ") isn't a number</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn2 == 0) {
             $this->errors .= "<em>Error: choose a member to input 'To'</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn1 == $this->cn2) {
             $this->errors .= "<em>Error: 'From' and 'To' cannot be the same</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn1 > 0) {
             $q = $dbc->prepare_statement("SELECT FirstName,LastName\n                    FROM custdata\n                    WHERE CardNo=? AND personNum=1");
             $r = $dbc->exec_statement($q, array($this->cn1));
             if ($dbc->num_rows($r) == 0) {
                 $this->errors .= "<em>Error: no such member: " . $this->cn1 . "</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
                 return True;
             }
             $row = $dbc->fetch_row($r);
             $this->name1 = $row['FirstName'] . ' ' . $row['LastName'];
         } else {
             $this->name1 = "Account Adjustment";
         }
         $q = $dbc->prepare_statement("SELECT FirstName,LastName\n                FROM {$FANNIE_OP_DB}{$dbc->sep()}custdata\n                WHERE CardNo=? AND personNum=1");
         $r = $dbc->exec_statement($q, array($this->cn2));
         if ($dbc->num_rows($r) == 0) {
             $this->errors .= "<em>Error: no such member: " . $this->cn2 . "</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         $row = $dbc->fetch_row($r);
         $this->name2 = $row['FirstName'] . ' ' . $row['LastName'];
     }
     return True;
 }
コード例 #6
0
ファイル: CoopCredMember.php プロジェクト: phpsmith/IS4C
 function SaveFormData($memNum)
 {
     global $FANNIE_ROOT;
     //$dbc = $this->db();
     global $FANNIE_URL;
     global $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS;
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         return '';
     }
     if (array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) && $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] != "") {
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     } else {
         return '';
     }
     // Test probably not necessary.
     if (!class_exists("CCredMembershipsModel")) {
         $dbc->logger("Had to include CCredMembershipsModel");
         include $FANNIE_ROOT . 'modules/plugins2.0/CoopCred/models/CCredMembershipsModel.php';
     }
     // Test probably not necessary.
     if (!class_exists("CCredProgramsModel")) {
         $dbc->logger("Had to include CCredProgramsModel");
         include $FANNIE_ROOT . 'modules/plugins2.0/CoopCred/models/CCredProgramsModel.php';
     }
     // For Coop Cred limit always 0.
     $limit = (int) FormLib::get_form_value('CC_limit', 0);
     $credit_ok = FormLib::get_form_value('use_coop_cred', '') !== '' ? 1 : 0;
     $programID = (int) FormLib::get_form_value('ccred_program', 0);
     $maxCreditBalance = FormLib::get_form_value('maxbal', 0.0);
     if ($maxCreditBalance > 0) {
         $maxCreditBalance = $maxCreditBalance * -1;
     }
     /* For Program Bank members programID is never > 0.
      */
     if ($programID > 0) {
         $ccmModel = new CCredMembershipsModel($dbc);
         $ccmModel->cardNo($memNum);
         $ccmModel->programID($programID);
         /* There should be one or none.
          * find() returns an array, possibly empty, so foreach is needed.
          */
         $test = false;
         $saved = 0;
         foreach ($ccmModel->find() as $obj) {
             $saved++;
             $obj->creditOK($credit_ok);
             $obj->creditLimit($limit);
             $obj->maxCreditBalance($maxCreditBalance);
             $now = date('Y-m-d H:i:s');
             $obj->modified($now);
             /*$obj->modifiedBy($auth-user-id);
              * Like $name = FannieAuth::checkLogin
              * then modifiedBy = FannieAuth::getUID($name)
              * Not sure if keeping mod/modBy here is worth it since
              *  FannieDispatch::logUsage is called by FD::go,
              *  but not for this class alone.
              * I only want to log actual changes, which I can't detect yet.
              */
             $test = $obj->save();
             if ($test === false) {
                 break;
             }
             /* During testing pTLCC writes string error messages to Fannie log.
              * There doesn't seem to be a mechanism for displaying them
              *  if they are returned here.
              */
             $laneTest = $obj->pushToLanesCoopCred();
             if ($laneTest != true) {
                 break;
             }
         }
         /* I.e. was it an update? */
         if ($saved > 0) {
             if ($test === false) {
                 return 'Error: Problem updating Coop Cred membership data.<br />';
             }
         } else {
             // Only add if being enabled.
             if ($credit_ok) {
                 $ccmModel->creditOK($credit_ok);
                 $ccmModel->creditLimit($limit);
                 $ccmModel->maxCreditBalance($maxCreditBalance);
                 $now = date('Y-m-d H:i:s');
                 $ccmModel->modified($now);
                 //$ccmModel->modifiedBy($auth-user-id);
                 /* Get (default) membership values, esp. *OK,
                  *  for fields not entered, from the Program.
                  */
                 $ccpModel = new CCredProgramsModel($dbc);
                 $ccpModel->programID($programID);
                 foreach ($ccpModel->find() as $prog) {
                     $ccmModel->inputOK($prog->inputOK());
                     $ccmModel->transferOK($prog->transferOK());
                     break;
                 }
                 $test = $ccmModel->save();
                 if ($test === false) {
                     return 'Error: Problem adding Coop Cred membership data.<br />';
                 }
                 /* During testing pTLCC writes string error messages to Fannie log.
                  * There doesn't seem to be a mechanism for displaying them
                  *  if they are returned here.
                  */
                 $laneTest = $ccmModel->pushToLanesCoopCred();
                 if ($laneTest != true) {
                     return 'Error: Problem adding Coop Cred membership data to lane.<br />';
                 }
             }
         }
     }
     // OK
     return '';
 }
コード例 #7
0
ファイル: LiabilityReport.php プロジェクト: phpsmith/IS4C
 function preprocess()
 {
     global $FANNIE_ROOT, $FANNIE_URL, $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS;
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         $this->errors[] = "The Coop Cred plugin is not enabled.";
         return True;
     }
     if (array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) && $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] != "") {
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     } else {
         $this->errors[] = "The Coop Cred database is not assigned in the " . "Coop Cred plugin configuration.";
         return True;
     }
     /**
       Whether invoked by form submission.
     */
     if (isset($_REQUEST['programID'])) {
         if ($_REQUEST['programID'] == "") {
             $this->errors[] = "Please choose a Program";
             $this->add_script("{$FANNIE_URL}src/CalendarControl.js");
             return True;
         }
         // 0 means all programs
         $programID = (int) $_REQUEST['programID'];
         if ($programID > 0) {
             $ccpModel = new CCredProgramsModel($dbc);
             $ccpModel->programID($programID);
             $prog = array_pop($ccpModel->find());
             if ($prog != null) {
                 $this->programID = $prog->programID();
                 $this->programName = $prog->programName();
                 $this->programBankID = $prog->bankID();
                 $this->programStartDate = preg_match("/^[12]\\d{3}-\\d{2}-\\d{2}/", $prog->startDate()) ? $prog->startDate() : '1970-01-01';
             } else {
                 $this->errors[] = "Error: Program ID {$programID} is not known.";
                 return True;
             }
         } else {
             $this->programID = $programID;
             $this->programName = "All Programs";
             $this->programBankID = 0;
             $this->programStartDate = '1970-01-01';
         }
         $dateFrom = FormLib::get_form_value('date1', '');
         $dateTo = FormLib::get_form_value('date2', '');
         $this->dateFrom = $dateFrom == '' ? $this->programStartDate : $dateFrom;
         $this->dateTo = $dateTo == '' ? date('Y-m-d') : $dateTo;
         /* Vars from the form
          */
         $this->reportType = FormLib::get_form_value('reportType', 'summary');
         $this->sortable = FormLib::get_form_value('sortable', '0');
         $this->subTotals = FormLib::get_form_value('subTotals', '0');
         $this->dbSortOrder = FormLib::get_form_value('dbSortOrder', 'DESC');
         if ($this->sortable == True) {
             if ($this->reportType == 'summary') {
                 $this->sort_column = 0;
                 // 1st column is 0
                 $this->sort_direction = 0;
                 // 0=asc 1=desc
             } else {
                 $this->sort_column = 3;
                 // 1st column is 0
                 /* 0=asc 1=desc 
                  * Name is always ASC. DESC applies to date.
                  */
                 $this->sort_direction = 0;
                 //$this->sort_direction = (($this->dbSortOrder == 'DESC')?1:0);
             }
         } else {
             $this->sortable = False;
         }
         /*
             Check if a non-html format has been requested.
             Does FannieReportPage already do this?
         */
         if (isset($_REQUEST['excel']) && $_REQUEST['excel'] == 'xls') {
             $this->report_format = 'xls';
             $this->has_menus(False);
         } elseif (isset($_REQUEST['excel']) && $_REQUEST['excel'] == 'csv') {
             $this->report_format = 'csv';
             $this->has_menus(False);
         }
         /* Which page content to create upon return to draw_page().
          */
         $this->content_function = "report_content";
     } else {
         $this->add_script("{$FANNIE_URL}src/CalendarControl.js");
         if (FormLib::get_form_value('pid', 0) != 0) {
             $this->pid = FormLib::get_form_value('pid', 0);
         }
     }
     return True;
     // preprocess()
 }