Пример #1
0
 function preprocess()
 {
     global $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS;
     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'] == "") {
         $this->errors .= _("Error: Coop Cred Database not named in Plugin Settings.");
         return True;
     }
     /* Get values from the Whole-Project (Plugin) config table.
      */
     $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     $config = new CCredConfigModel($dbc);
     $config->configID(1);
     if (!$config->load()) {
         $this->errors .= _("Error: Coop Cred configuration not available.");
         return True;
     }
     $this->dummyTenderCode = $config->dummyTenderCode();
     $this->dummyDepartment = $config->dummyDepartment();
     $this->deptMin = $config->deptMin();
     $this->deptMax = $config->deptMax();
     $this->dummyBanker = $config->dummyBanker();
     $this->bankerMin = $config->bankerMin();
     $this->bankerMax = $config->bankerMax();
     /* For CCredPrograms.modifiedBy
      */
     $this->authUserNumber = 0;
     $authName = FannieAuth::checkLogin();
     if (!($authName == 'null' || $authName == 'init' || $authName == False)) {
         $this->authUserNumber = FannieAuth::getUID($authName);
     }
     /* Support ajax calls to this program.
      * If there is a form submission with an action go do it.
      * The form submission may be via AJAX instead of <form ...>
      *  with action= in the query string with other parameters.
      */
     if (FormLib::get_form_value('action') !== '') {
         $this->ajax_response(FormLib::get_form_value('action'));
         /* How to handle errors/problems esp. in save?
          * Possibly code readinessCheck()
          */
         return False;
     }
     /* If the call was not by form, e.g. from the initial menu
      * or the <form action=> is '' (when does that happen?)
      * FanniePage::draw_page() continues to $this->body_content()
      *  which returns the the program-select form.
      */
     return True;
     // 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.
      * Maybe better as array.
      */
     $returnMessage = "";
     /* These are from the query (parameters) string in the AJAX request
      *  and are the same as the input form id= values.
      */
     $configno = FormLib::get_form_value('configno', 0);
     $dummytender = FormLib::get_form_value('dummytender', '');
     $dummydept = FormLib::get_form_value('dummydept', 0);
     $deptmin = FormLib::get_form_value('deptmin', 0);
     $deptmax = FormLib::get_form_value('deptmax', 0);
     $dummybanker = FormLib::get_form_value('dummybanker', 0);
     $bankermin = FormLib::get_form_value('bankermin', 0);
     $bankermax = FormLib::get_form_value('bankermax', 0);
     $membermin = FormLib::get_form_value('membermin', 0);
     $membermax = FormLib::get_form_value('membermax', 0);
     $isnew = FormLib::get_form_value('isnew', 9);
     /* Check for problems.
      * See CoopCredProgramEditor for examples.
      */
     $sMessage = "";
     /* Each check */
     /* 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 Config proper.
      */
     $config = new CCredConfigModel($dbc);
     $config->configID($configno);
     $config->dummyTenderCode($dummytender);
     $config->dummyDepartment($dummydept);
     $config->deptMin($deptmin);
     $config->deptMax($deptmax);
     //
     $config->dummyBanker($dummybanker);
     $config->bankerMin($bankermin);
     $config->bankerMax($bankermax);
     //
     $config->regularMemberMin($membermin);
     $config->regularMemberMax($membermax);
     //
     $config->modifiedBy($this->authUserNumber);
     $config->modified(date('Y-m-d H:i:s'));
     /* save() decides UPDATE vs INSERT based on whether configID already
      * exists.
      */
     $saved = $config->save();
     if ($isnew == 1) {
         if ($saved === False) {
             echo 'Error: could not create Configuration';
             return;
         }
     } else {
         if ($saved === False) {
             echo 'Error: could not save the changes to the Configuration';
             return;
         } else {
             $returnMessage .= sprintf("\nSaved Configuration (#%d)", $configno);
         }
     }
     $returnMessage = preg_replace("/^\n+/", "", $returnMessage);
     echo $returnMessage;
     // ajax_save_program()
 }
Пример #3
0
 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()
 }
Пример #4
0
 function ShowEditForm($memNum, $country = "US", $inProgramID = -1)
 {
     global $FANNIE_URL;
     global $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS;
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         $msg = "Problem: The '" . $this->pluginName . "' plugin is not enabled.";
         return $this->FormatReturnMessage($msg);
     }
     if (array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) && $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] != "") {
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     } else {
         $msg = "Problem: Connection to the database for the '" . $this->pluginName . "' plugin failed.";
         return $this->FormatReturnMessage($msg);
     }
     $config = new CCredConfigModel($dbc);
     $config->configID(1);
     $loadOK = $config->load();
     if (!$loadOK) {
         $msg = "Problem: Please 'Configure Coop Cred' from the Coop Cred Admin menu.";
         return $this->FormatReturnMessage($msg);
     } else {
         $this->regularMemberMin = $config->regularMemberMin();
         $this->regularMemberMax = $config->regularMemberMax();
     }
     /* Needs to get:
      * -all programs or
      * -all active programs
      * regardless whether member is in them
      * distinguish the ones he/does belong to by CAPS or colour or something
      * set SELECTED for the first one he/she belongs to, else Choose
      * and show the current balance for that
      * and set the default params for:
      * -transfer
      * -fix
      * -Activity Report
      * to that.
      */
     $programID = 0;
     $programBankNumber = 0;
     /* Get all programs first, then see if the member is in them.
      */
     $progQ = "SELECT programID, programName, bankID\n            FROM CCredPrograms\n            WHERE active =1\n            ORDER BY programName ASC";
     $progS = $dbc->prepare_statement($progQ);
     $progR = $dbc->exec_statement($progS, array());
     $ccred_programs = array();
     $pID = '';
     // format: P01
     $firstMpID = '';
     // a $pID
     $programCount = 0;
     while ($progW = $dbc->fetch_row($progR)) {
         $programCount++;
         $pID = sprintf("P%02d", $progW['programID']);
         if ($programCount == 1) {
             $firstMpID = $pID;
         }
         $ccred_programs["{$pID}"] = array('programID' => $progW['programID'], 'programName' => $progW['programName'], 'bankID' => $progW['bankID'], 'creditOK' => 0, 'membershipID' => 0, 'balance' => NULL, 'maxCreditBalance' => 0, 'isDefault' => 0);
     }
     /* Then get balance for the ones the member belongs to.
      * Decide which one will be displayed, the default,
      *  in order of preference.
      *  1. The first one the member belongs to where creditOK is True,
      *      i.e. that he/she can purchase with.
      *  2. The first one he/she belongs to.
      *  3. The first one that exists.
      *  4. Override with parameter $inProgramID.
      *
      */
     $infoQ = "SELECT m.programID, m.cardNo, m.creditOK, m.membershipID,\n                    m.maxCreditBalance,\n                    b.balance\n                FROM CCredMemberships AS m\n                JOIN CCredLiveBalance AS b ON m.cardNo = b.cardNo\n                    AND m.programID = b.programID\n                JOIN CCredPrograms AS p ON m.programID = p.programID\n                WHERE m.cardNo =?\n                    AND p.active =1";
     $infoS = $dbc->prepare_statement($infoQ);
     $infoR = $dbc->exec_statement($infoS, array($memNum));
     $membershipCount = 0;
     $firstCreditOK = $inProgramID > -1 ? 1 : 0;
     // This may not be getting a real value if Member does not belong to any yet.
     if ($firstMpID == '') {
         // Means there are no Programs
         $pID = sprintf("P%02d", 0);
         $ccred_programs["{$pID}"] = array('programID' => 0, 'programName' => "No Programs Exist", 'bankID' => 0, 'creditOK' => 0, 'membershipID' => 0, 'balance' => NULL, 'maxCreditBalance' => 0, 'isDefault' => 1);
     } else {
         $pID = $firstMpID;
         // format: P01
     }
     $defaultMembership = $inProgramID > -1 ? sprintf("P%02d", $inProgramID) : $pID;
     $firstPID = '';
     // a $pID
     while ($infoW = $dbc->fetch_row($infoR)) {
         $membershipCount++;
         $pID = sprintf("P%02d", $infoW['programID']);
         if ($membershipCount == 1) {
             $firstPID = $pID;
         }
         /* ?Details for programs other than the default were gathered
          * for when I was going to compose JS to do the program change.
          */
         $ccred_programs["{$pID}"]['balance'] = $infoW['balance'];
         $ccred_programs["{$pID}"]['creditOK'] = $infoW['creditOK'];
         $ccred_programs["{$pID}"]['maxCreditBalance'] = $infoW['maxCreditBalance'];
         $ccred_programs["{$pID}"]['membershipID'] = $infoW['membershipID'];
         if ($inProgramID > -1) {
             if ($infoW['programID'] == $inProgramID) {
                 $ccred_programs["{$pID}"]['isDefault'] = 1;
                 $defaultMembership = $pID;
                 $programID = $ccred_programs["{$pID}"]['programID'];
                 $programName = $ccred_programs["{$pID}"]['programName'];
                 $programBankNumber = $ccred_programs["{$pID}"]['bankID'];
                 $firstCreditOK = 1;
                 continue;
             }
         } else {
             if ($ccred_programs["{$pID}"]['creditOK'] && $firstCreditOK == 0) {
                 $ccred_programs["{$pID}"]['isDefault'] = 1;
                 $defaultMembership = $pID;
                 $programID = $ccred_programs["{$pID}"]['programID'];
                 $programName = $ccred_programs["{$pID}"]['programName'];
                 $programBankNumber = $ccred_programs["{$pID}"]['bankID'];
                 $firstCreditOK = 1;
             }
         }
     }
     /* If Member belongs to at least one but none is inputOK yet
      *  default to the first one belonged to.
      */
     if ($membershipCount > 0 && $firstCreditOK == 0) {
         $ccred_programs["{$firstPID}"]['isDefault'] = 1;
         $defaultMembership = $firstPID;
         $programID = $ccred_programs["{$firstPID}"]['programID'];
         $programName = $ccred_programs["{$firstPID}"]['programName'];
         $programBankNumber = $ccred_programs["{$firstPID}"]['bankID'];
     }
     /* If Member belongs to none $defaultMembership is still "".
      * The formlet can refer to Programs that Member doesn't belong to
      *  but not to values that come from CCredMemberships.
      *  The membership values are dummy.
      */
     $programMemberType = $memNum == $programBankNumber ? "{$programName}" : "Member";
     $ret = "";
     /* Later, AJAX-driven, calls ($inProgramID > -1) re-populate this <div>
      *  but must not write it again.
      *  CSS is temporary until boostrap coding is done.
      */
     if ($inProgramID == -1) {
         $ret .= "<style type='text/css'>\n.MemFormTable th {\n    font-size: 75%;\n    text-align: right;\n    color: #fff;\n    padding: 0 5px 0 2px;\n    border: solid white 2px;\n}\n.MemFormTable td {\n    padding: 2px 2px 2px 2px;\n}\n/* The interveneing ccredmemdiv prevents bootstrap's\n    * gradient from appearing.\n */\n.ccredpanelhead {\n    background-color: #f5f5f5;\n    border-bottom: 1px solid #ddd;\n}\n</style>";
         $ret .= "<div class='panel panel-default'>";
         $ret .= "<div id='ccredmemdiv'>";
     }
     $ret .= "<div class=\"panel-heading ccredpanelhead\">Coop Cred - {$programMemberType}";
     //</div>";
     $ret .= " <a onclick=\"\$('#_fhtt14102004').toggle();return false;\" href=''>" . "<img title='Let the Member make purchases against money in an account " . "(Click for more)' src='{$FANNIE_URL}src/img/buttons/help16.png'>" . "</a>";
     $ret .= "</div><!-- /.panel-heading -->";
     $ret .= "<div class=\"panel-body\">";
     /* For bootstrapped v.1 retain the table coding.
      */
     $ret .= "<table class='MemFormTable' border='0' width='100%'>";
     if ($memNum != $programBankNumber) {
         $ret .= "<tr>";
         $ret .= "<td colspan=3>";
         if ($memNum >= $this->regularMemberMin && $memNum <= $this->regularMemberMax) {
             $ret .= "<select id='ccred_program' name='ccred_program' " . "onchange='memProgramChange();' >";
             $ret .= "<option value='0'>Choose Program</option>";
             foreach ($ccred_programs as $pID => $prog) {
                 $p_sel = ($membershipCount > 0 || $inProgramID > -1) && $pID == $defaultMembership ? ' selected="1" ' : '';
                 $o_style = $prog['creditOK'] == 1 ? "style='font-weight:bold;'" : "";
                 $ret .= "<option value='{$prog['programID']}'{$p_sel}{$o_style}>" . "{$prog['programName']}</option>";
             }
             $ret .= "</select>";
         } else {
             $ret .= " &nbsp; ";
         }
         $ret .= "</td>";
         $ret .= "<th title='The amount of Coop Cred the member has to use.'>Current Balance</th>";
         $ret .= "<th title='The maximum Coop Cred the member may accumulate.'>Max Balance</th>";
         $ret .= "</tr>";
     }
     $ret .= "<tr>";
     $ucc = $ccred_programs["{$defaultMembership}"]['creditOK'] ? ' checked="" ' : '';
     $uccDisabled = $memNum == $programBankNumber ? ' disabled ' : "";
     $ret .= "<th title='Allow/prevent the member&apos;s use of the selected type of Coop Cred.'>Use Coop Cred</th>";
     $ret .= sprintf('<td><input type="checkbox" name="use_coop_cred" %s %s/>
             </td>', $ucc, $uccDisabled);
     // In Coop Cred $limit is always 0.
     $limit = 0;
     $ret .= "<input type='hidden' name='CC_limit' value='{$limit}'>";
     if ($memNum == $programBankNumber) {
         $ret .= "<th title='The amount of Coop Cred the member has to use.'>Current Balance</th>";
     } else {
         $ret .= "<td> &nbsp; </td>";
     }
     $ret .= sprintf('<td id="cbal" name="cbal">%.2f</td>', $ccred_programs["{$defaultMembership}"]['balance'] * -1);
     if ($memNum == $programBankNumber) {
         $today = date('Y-m-d');
         $cellContent = "<p style='margin:0em; font-family:Arial;line-height:1.0em;'>\n                <a href=\"{$FANNIE_URL}{$this->pluginHome}reports/ProgramEvents/" . "ProgramEventsReport.php?date1=&amp;date2=&amp;card_no={$memNum}" . "&amp;sortable=on" . "&amp;programID={$programID}\"\n                title='List inputs to and payments from the program before today'\n                target='_coop_cred_events'\n                >Event History</a>\n                <br />\n                <a href=\"{$FANNIE_URL}{$this->pluginHome}reports/ProgramEvents/" . "ProgramEventsReport.php?date1={$today}&amp;date2={$today}" . "&amp;sortable=on" . "&amp;other_dates=on&amp;submit=Submit&amp;card_no={$memNum}" . "&amp;programID={$programID}\"\n                title='List inputs to and payments from the program today'\n                target='_coop_cred_events'\n                >Events Today</a>\n                </p>\n                ";
     } else {
         $template = '<input type="text" size=8 maxlength=10 id="maxbal" ' . 'name="maxbal" value="%.2f" >';
         $cellContent = sprintf("{$template}", $ccred_programs["{$defaultMembership}"]['maxCreditBalance'] * -1);
     }
     $ret .= "<td>" . $cellContent;
     $ret .= "</td>";
     $ret .= "</tr>";
     $ret .= "<tr>";
     if ($memNum == $programBankNumber) {
         $transferTitle = 'Move funds to a member account or return them to ' . 'the Program Account.';
     } else {
         $transferTitle = 'Get funds for the member from, or return the ' . 'member&apos;s funds to, the Program Account or another member.';
     }
     if ($programID == 0) {
         $transferTitle .= "\nAdd the member to a Program and Save before " . "doing a Transfer.";
     }
     $args1 = "memIN={$memNum}&amp;memEDIT={$memNum}&amp;" . "programID={$programID}";
     $ret .= "<td colspan=\"2\"><a id='tlink' name='tlink'\n            href=\"{$FANNIE_URL}{$this->pluginHome}membership/CoopCredTransferTool.php?{$args1}\"\n            title='{$transferTitle}'\n            >Transfer Coop Cred</a></td>";
     $args2 = "memIN={$memNum}&amp;memEDIT={$memNum}&amp;" . "programID={$programID}";
     $ret .= "<td><a id='flink' name='flink'\n            href=\"{$FANNIE_URL}{$this->pluginHome}membership/CoopCredJiggerTool.php?{$args2}\"\n            title='Fix errors and problems'\n            >Fix Coop Cred</a></td>";
     /* In this program only the Program Account may accept inputs.
      * -> Needs to come from Program
      */
     $ret .= "<td colspan='2' style='text-align:center;'>";
     if ($memNum == $programBankNumber) {
         $args3 = $args2;
         $ret .= "<a id='ilink' name='ilink'\n                href=\"{$FANNIE_URL}{$this->pluginHome}membership/CoopCredInputTool.php?{$args3}\"\n                title='Input (deposit) external funds to the Program Account'\n                >Input Coop Cred</a>";
     } elseif ($memNum >= $this->regularMemberMin && $memNum <= $this->regularMemberMax) {
         $reportLink = "<a id='arlink' name='arlink' " . "href=\"{$FANNIE_URL}{$this->pluginHome}reports/" . "Activity/ActivityReport.php?" . "memNum={$memNum}&amp;programID={$programID}\"" . " title='List earnings and purchases for this member'" . " target='_blank'" . "><p style='margin:0em; font-family:Arial;line-height:1.0em;'>" . "Activity Report</p></a>";
         $ret .= $reportLink;
     } else {
         $ret .= " &nbsp; ";
     }
     $ret .= "</td>";
     $ret .= "</tr>";
     $ret .= "</table>";
     //$ret .= "</fieldset>";
     $ret .= "</div><!-- /.panel-body -->";
     if ($inProgramID == -1) {
         /* The fieldset goes in the ccremdiv container. */
         $ret .= "</div> <!-- /ccredmemdiv -->";
         $ret .= '<fieldset id="_fhtt14102004" style="display:none; width:440px;">' . "Let the Member make purchases against money in an account. " . "<br />A Member may have an account in (be a member of) more than one Program." . "<br />'Balance' shows how much is left in the account." . "<br />Un-ticking 'OK' will suspend the account when member data is refreshed on lanes. " . "<br />Use the 'Transfer' link to add money to the account from the Program Bank." . "<br />The Member is allowed to use all accounts in the Program dropdown " . "that are in <b>bold</b>." . "<br />To add a Member to a Program (allow him/her to use it) " . "select the Program, tick 'Use Coop Cred' and click 'Save'" . "<!-- br />The Transfer, Fix and Activity links are for the Program that " . "is selected when the form initially displays. " . "To use Transfer etc. for another Program, temporarily untick 'Use Coop Cred', " . "click Save, and Edit the same Member again." . "This will expose the next Program the Member belongs to." . "<br />After making and Saving the changes, select the initial Program again, " . "tick 'Use Coop Cred' and click Save." . " -->" . "</fieldset>";
         $ret .= sprintf("<input type='hidden' id='memNum' name='memNum' value='%d' />", $memNum);
         $ret .= sprintf("<input type='hidden' id='pathTo' name='pathTo' value='%s' />", $FANNIE_URL . $this->pluginHome . 'membership/');
         $ret .= "</div><!-- /.panel .panel-default -->";
         $ret .= $this->getEditJavascript();
     }
     return $ret;
     // ShowEditForm()
 }