private function ajax_display_program($id) { global $FANNIE_PLUGIN_SETTINGS, $FANNIE_URL, $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']); /* A set of vars with the ?default values for all fields this editor handles. */ $pProgramID = 0; $pProgramName = ''; $pActive = 0; $pStartDate = ''; $pEndDate = ''; // $pTenderType = ''; $pTenderName = ''; $pTenderKeyCap = ''; $pInputTenderType = ''; // $pPaymentDepartment = 0; $pPaymentName = ''; $pPaymentKeyCap = ''; $pBankID = 0; // $pCreditOK = 0; $pMaxCreditBalance = 0; // 10,2 $pInputOK = 0; $pTransferOK = 0; /* Prepare to display existing record. * -1 means create new record */ if ($id != -1) { $program = new CCredProgramsModel($dbc); // Supply key for the record. $program->programID($id); $program->load(); // Assuming the lookup/load didn't fail, load values to local vars. // First row $pProgramName = $program->programName(); $pActive = $program->active(); $pStartDate = $program->startDate(); $pEndDate = $program->endDate(); if ($pEndDate == "NULL" || $pEndDate == "0000-00-00") { $pEndDate = ""; } // Second row $pTenderType = $program->tenderType(); $pTenderName = $program->tenderName(); $pTenderKeyCap = $program->tenderKeyCap(); $pInputTenderType = $program->inputTenderType(); // Third row $pPaymentDepartment = $program->paymentDepartment(); $pPaymentName = $program->paymentName(); $pPaymentKeyCap = $program->paymentKeyCap(); $pBankID = $program->bankID(); // Fourth row $pCreditOK = $program->creditOK(); $pMaxCreditBalance = $program->maxCreditBalance(); $pInputOK = $program->inputOK(); $pTransferOK = $program->transferOK(); } $OP = $FANNIE_OP_DB . $dbc->sep(); $tenders = array(); /* Default for new Programs * Can be saved to CCredPrograms but not to tenders. * Program cannot be used for e.g. membership assignments until a real * value is set up and chosen, i.e. while this is in use. */ $tenders["{$this->dummyTenderCode}"] = "Dummy Tender"; $tSize = 0; if ($id == -1) { $pTenderType = $this->dummyTenderCode; $pTenderName = $tenders["{$this->dummyTenderCode}"]; $tSize++; $pInputTenderType = 'PI'; } $q = "SELECT TenderCode, TenderName\n FROM {$OP}tenders\n WHERE TenderCode NOT IN ('CA','CK','CC','DC','MI','CX','TV')\n ORDER BY TenderCode"; $p = $dbc->prepare_statement($q); $resp = $dbc->exec_statement($p); $tenderRet = ""; $tSelected = ''; if ($pTenderType == "{$this->dummyTenderCode}") { $tenderRet .= sprintf("<option value='%s'%s>%s %s</option>", $pTenderType, "selected=''", $pTenderType, $tenders["{$pTenderType}"]); } $iSize = 0; $iTenders = array(); $iSelected = ''; $inputRet = ''; $tenderStyle = " style='color:black;' "; while ($row = $dbc->fetch_row($resp)) { // --> 'Q' to come from project configuration. if (substr($row['TenderCode'], 0, 1) == 'Q') { $tSize++; $tenders["{$row['TenderCode']}"] = $row['TenderName']; $tenderRet .= sprintf("<option %s value='%s'%s>%s %s</option>", $tenderStyle, $row['TenderCode'], $tSelected = $row['TenderCode'] == $pTenderType ? " selected=''" : '', $row['TenderCode'], $row['TenderName']); if ($row['TenderCode'] == $pTenderType && $pTenderName == "") { $pTenderName = $row['TenderName']; } } else { $iSize++; $iTenders["{$row['TenderCode']}"] = $row['TenderName']; $inputRet .= sprintf("<option value='%s'%s>%s %s</option>", $row['TenderCode'], $iSelected = $row['TenderCode'] == $pInputTenderType ? " selected=''" : '', $row['TenderCode'], $row['TenderName']); } } $tSize = $tSize > 4 ? 4 : $tSize; $tenderRet = "<select id='tendertype' name='tendertype' size='{$tSize}'>" . $tenderRet . "</select>"; $iSize = $iSize > 1 ? 1 : $iSize; $inputRet = "<select id='inputtender' name='inputtender' size='{$iSize}'>" . $inputRet . "</select>"; $departments = array(); /* Default for new Programs * Can be saved to CCredPrograms but not to departments. * Program cannot be used for e.g. membership assignments until a real * value is set up and chosen, i.e. while this is in use. */ $departments[$this->dummyDepartment] = "Dummy Department"; $dSize = 0; if ($id == -1) { $pPaymentDepartment = $this->dummyDepartment; $pPaymentName = $departments[$this->dummyDepartment]; $dSize++; } $q = "SELECT dept_no, dept_name\n FROM {$OP}departments\n WHERE dept_no BETWEEN {$this->deptMin} AND {$this->deptMax}\n ORDER BY dept_no"; $p = $dbc->prepare_statement($q); $resp = $dbc->exec_statement($p); $departmentRet = ""; $dSelected = ''; if ($pPaymentDepartment == $this->dummyDepartment) { $departmentRet .= sprintf("<option value='%s'%s>%s %s</option>", $pPaymentDepartment, "selected=''", $pPaymentDepartment, $departments[$pPaymentDepartment]); } while ($row = $dbc->fetch_row($resp)) { $dSize++; $departments["{$row['dept_no']}"] = $row['dept_name']; $departmentRet .= sprintf("<option value='%s'%s>%s %s</option>", $row['dept_no'], $dSelected = $row['dept_no'] == $pPaymentDepartment ? " selected=''" : '', $row['dept_no'], $row['dept_name']); if ($row['dept_no'] == $pPaymentDepartment && $pPaymentName == "") { $pPaymentName = $row['dept_name']; } } $dSize = $dSize > 4 ? 4 : $dSize; $departmentRet = "<select id='paymentid' name='paymentid' size='{$dSize}'>" . $departmentRet . "</select>"; $bankers = array(); /* Default for new Programs * Can be saved to CCredPrograms but not to custdata. * Program cannot be used for e.g. membership assignments until a real * value is set up and chosen, i.e. while this is in use. */ $bankers[$this->dummyBanker] = "Dummy Banker"; $bSize = 0; if ($id == -1) { $pBankID = $this->dummyBanker; $bSize++; } $q = "SELECT CardNo, CONCAT(FirstName, ' ', LastName) as bname\n FROM {$OP}custdata\n WHERE CardNo BETWEEN {$this->bankerMin} AND {$this->bankerMax}\n ORDER BY CardNo"; $p = $dbc->prepare_statement($q); $resp = $dbc->exec_statement($p); $bankerRet = ""; $dSelected = ''; if ($pBankID == $this->dummyBanker) { $bankerRet .= sprintf("<option value='%s'%s>%s %s</option>", $pBankID, "selected=''", $pBankID, $bankers[$pBankID]); } while ($row = $dbc->fetch_row($resp)) { $bSize++; $bankers["{$row['CardNo']}"] = $row['bname']; $bankerRet .= sprintf("<option value='%s'%s>%s %s</option>", $row['CardNo'], $dSelected = $row['CardNo'] == $pBankID ? " selected=''" : '', $row['CardNo'], $row['bname']); } $bSize = $bSize > 4 ? 4 : $bSize; $bankerRet = "<select id='bankid' name='bankid' size='{$bSize}'>" . $bankerRet . "</select>"; /* $hb (helpbit) is an array keyed on the id= of the input being described. * Each element is an array with 2 elements: * ['a'] which contains the <a onclick=target-id><img></a> * ['t'] containing the <fieldset id=target-id>long help</fieldset> */ $hbPrefix = '_CCPE'; $hbNumber = 1000; $hb = array(); $hbShortMessage = array(); $hbLongMessage = array(); $hbIcon = "{$FANNIE_URL}src/img/buttons/help16.png"; $hbMore = " " . _("(Click for more)"); $hbNoMore = ""; $hbLongWidth = 50; // em /* Steps for each HelpBit */ /* Steps for each HelpBit * Copy this template and fill it in. $hbKey = 'foo'; $hbKeys[] = $hbKey; $hbShortMessage["$hbKey"] = "One " . "Two." . "" . ""; $hbLongMessage["$hbKey"] = "{$hbShortMessage[$hbKey]}" . "<br />One " . "two " . "<br /> " . "" . ""; */ $hbKey = 'isactive'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "Tick to let activity in the Program take place; un-tick to suspend."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />Un-ticking will prevent any charges or payments being made in the Program, " . "in other words, members will not be able to use it." . "<br />It may sometimes be necessary to halt activity in order to deal with a problem." . "<br />Un-ticking (suspending) overrides the Start Date." . "<br />The box must be ticked for any activity in the Program to take place." . "<br />Ticking does not override Start or End Dates." . "<br />It may take a few minutes for the change to take effect on the lanes." . "<br />The change will not take effect on any lane running in 'Standalone' mode." . "" . ""; $hbKey = 'startdate'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "The first day on which charges and payments in the Program may be made."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />It is necessary to have a Start Date for activity in the Progream to begin to " . "take place. " . "<br />If you want to suspend activity in the program un-tick the Active checkbox; " . "that will override the Start Date."; "<br />Some reports rely on the Start Date so if it is changed to later than when the " . "first activity took place the report may not be accurate." . "<br />On the other hand, Start Date could be changed to, with care, mark a new epoch " . "in the life of the Program." . "<br />Format: YYYY-MM-DD" . ""; $hbKey = 'enddate'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "The last day on which charges and payments in the Program may be made."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />If you want to suspend activity in the program un-tick the Active checkbox." . "<br />If the End Date has passed the Active status will not override it; " . "if you want to extend the Program set the End Date to later." . "<br />An empty End Date means the Program will run indefinitely." . "<br />Format: YYYY-MM-DD" . ""; /* Second row helps $ret .= "<th colspan=1>Tender{$hb['tendertype']['a']}</th>"; $ret .= "<th colspan=1>Tender Name{$hb['tendername']['a']}</th>"; $ret .= "<th colspan=1>Tender Keycap{$hb['tenderkeycap']['a']}</th>"; $ret .= "<th colspan=1>Input Tender{$hb['inputtender']['a']}</th>"; */ $hbKey = 'tendertype'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "The tender that is used for purchases in this Program."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />A tender may only be used in one Program." . "<br />If the tender for this Program doesn't exist yet " . "you can add it using the " . "<a href='{$FANNIE_URL}/admin/Tenders/' target='_TE' " . "style='font-size:1.2em; font-weight:bold;'>" . "Fannie Tenders Editor</a> " . "and then select this Program again for editing " . "to make the new Tender appear in the list." . ""; $hbKey = 'tendername'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "The name of the tender at left as it will appear on receipts."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />This name will appear with the Tender code in the Tender list." . "<br />To see the result in the list after Saving," . "select a different Program and then select this one again." . ""; $hbKey = 'tenderkeycap'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "A very short abbreviation for the tender."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />Ideally, short enough to be used on a keyboard keycap." . "" . "<br />long2"; $hbKey = 'inputtender'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "The tender used for inputs from external sources."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />This is usually the same for all Programs at a co-op." . "" . ""; /* Third row helps $ret .= "<th colspan=1>Payment{$hb['paymentid']['a']}</th>"; $ret .= "<th colspan=1>Payment Name{$hb['paymentname']['a']}</th>"; $ret .= "<th colspan=1>Payment Keycap{$hb['paymentkeycap']['a']}</th>"; $ret .= "<th colspan=1>Bank{$hb['bankid']['a']}</th>"; */ $hbKey = 'paymentid'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "The department that is used for payments and other transfers in this Program."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />A payment department may only be used in one Program." . "<br />If the department for this Program doesn't exist yet " . "you can add it using the " . "<a href='{$FANNIE_URL}item/departments/DepartmentEditor.php' target='_DE' " . "style='font-size:1.2em; font-weight:bold;'>" . "Fannie Deparments Editor</a> " . "and then select this Program again for editing " . "to make the new Payment Department appear in the list." . ""; $hbKey = 'paymentname'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "The name that will appear on reports and receipts."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />This name will appear with the Department code in the " . "Input/Payment Department list." . "<br />To see the result in the list after Saving," . "select a different Program and then select this one again." . "" . ""; $hbKey = 'paymentkeycap'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "A very short abbreviation for the department."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />Ideally, short enough to be used on a keyboard keycap." . "" . ""; $hbKey = 'bankid'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "The pseudo-Member that receives inputs from external sources " . "and distributes to Program Members."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />A Banker may only serve one Program." . "<br />If the Banker for this Program doesn't exist yet " . "you can add it using the " . "<a href='{$FANNIE_URL}mem/MemberEditor.php?memNum={$pBankID}' target='_ME' " . "style='font-size:1.2em; font-weight:bold;'>" . "Members Editor</a> " . "and then select this Program again for editing " . "to make the new Banker Member appear in the list." . "<br />Also use the Member Editor to change the name of the Banker." . ""; /* Fourth row helps $ret .= "<th colspan=1>Credit OK{$hb['creditok']['a']}</th>"; $ret .= "<th colspan=1>Maximum Credit{$hb['maxcredit']['a']}</th>"; $ret .= "<th colspan=1>Input OK{$hb['inputok']['a']}</th>"; $ret .= "<th colspan=1>Transfer OK{$hb['transferok']['a']}</th>"; */ $hbKey = 'creditok'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "The default for whether Members of the Program may purchase with Coop Cred."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />Un-ticking it <i>at the Member level</i> is used to suspend the Member's " . "use of the Program." . "<br />Changing this only affects new memberships in the Program; " . "it does not change existing memberships." . "<br />To suspend activity in the Program un-tick the Active checkbox." . "" . ""; $hbKey = 'maxcredit'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "The default maximum amount of Coop Cred a Member of the Program may have."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />This supports management of fraud." . "<br />It may be overridden for each Member." . "" . ""; $hbKey = 'inputok'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "The default for whether Members may put money into their own accounts."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />For some Programs all amounts must be transferred to Members by the Banker." . "<br />It may be overridden for each Member." . "<br />Changing this only affects new memberships in the Program; " . "it does not change existing memberships." . "" . ""; $hbKey = 'transferok'; $hbKeys[] = $hbKey; $hbShortMessage["{$hbKey}"] = "The default for whether Members of the Program may transfer Coop Cred to another Member."; $hbLongMessage["{$hbKey}"] = "{$hbShortMessage[$hbKey]}" . "<br />It may be overridden for each Member." . "<br />Changing this only affects new memberships in the Program; " . "it does not change existing memberships." . "<br />16Nov2014 It is not supported at this time, has no effect." . "" . ""; /* After all the help messages are defined, compose the code that uses them. * Insert the ['a'] like: <th>Active{$hb['isactive']['a']}</th> * The ['t']s are automatically placed in a certain area of the page. */ $fieldsetStyle = ""; foreach ($hbKeys as $hbKey) { $hbTarget = "{$hbPrefix}" . ++$hbNumber; if (isset($hbLongMessage["{$hbKey}"]) && $hbLongMessage["{$hbKey}"] != "") { $anyMore = $hbMore; $onClick = " onclick=\"\$('#{$hbTarget}').toggle();return false;\" "; $helpCloser = "<br /><a href='' {$onClick} style='font-weight:bold;'>Close</a>"; } else { $anyMore = $hbNoMore; $onClick = ""; } $hb["{$hbKey}"]['a'] = " <a " . $onClick . "href=''>" . "<img title='{$hbShortMessage["{$hbKey}"]}{$anyMore}' src='{$hbIcon}'>" . "</a>"; $hb["{$hbKey}"]['t'] = "<fieldset id='{$hbTarget}' name='{$hbTarget}' " . "class='helpbit' " . "style='width:{$hbLongWidth}em;'" . ">" . $hbLongMessage["{$hbKey}"] . $helpCloser . "</fieldset>"; } /* This and similar horrors are to overcome bootstrap * until I have time to figure out how to code this * in a bootstrap-compliant way. */ $tableStyle = " style='border-spacing:5px; border-collapse: separate;'"; $ret = "<table id='edtable'{$tableStyle}>"; // First row of headings. $ret .= "<tr class='vTop'>"; $ret .= "<th>Program ID</th>"; $ret .= "<th colspan=1>Name</th>"; $ret .= "<th>Active{$hb['isactive']['a']}</th>"; $ret .= "<th>Program Start{$hb['startdate']['a']}</th>"; $ret .= "<th>Program End{$hb['enddate']['a']}</th>"; $ret .= "</tr>"; // First row of inputs. $ret .= "<tr class='vTop'>"; $ret .= "<td class='iCenter'>"; if ($id == -1) { $ret .= _("Will be assigned upon Save"); $ret .= "<input type=hidden id=progno name=progno value='' />"; } else { $ret .= $id; } $ret .= "</td>"; $ret .= "<td colspan=1 class=''><input type=text maxlength=30 id=progname " . "value=\"{$pProgramName}\" /></td>"; /* active */ $ret .= "<td class='iCenter'><input type=checkbox id=isactive " . ($pActive == 1 ? 'checked' : '') . " /></td>"; /* startDate These alone are not sufficient for the bootstrap implementation. '<div class="form-group">' . "<input type=text id=startdate name=startdate class='form-control date-field' " . "</div>" . */ $ret .= "<td>" . "<input type=text size=8 maxlength=10 id=startdate name=startdate " . "onclick='showCalendarControl(this);' " . "value='{$pStartDate}' " . "/>" . "</td>"; /* endDate */ $ret .= "<td><input type=text size=8 maxlength=10 id=enddate name=enddate\n onclick='showCalendarControl(this);'\n value='{$pEndDate}' /></td>"; $ret .= "</tr>"; /* Second row of headings. */ $ret .= "<tr class='vBottom'>"; $ret .= "<th colspan=1><br />Tender{$hb['tendertype']['a']}</th>"; $ret .= "<th colspan=1><br />Tender Name{$hb['tendername']['a']}</th>"; $ret .= "<th colspan=1 class='headLeft'>Tender Keycap{$hb['tenderkeycap']['a']}</th>"; $ret .= "<th colspan=1>External Input<br />Tender{$hb['inputtender']['a']}</th>"; $ret .= "<th colspan=1> </th>"; $ret .= "</tr>"; /* Second row of inputs. */ $ret .= "<tr class='vTop'>"; $ret .= "<td>{$tenderRet}</td>"; $ret .= "<td><input type=text size=22 maxlength=25 id=tendername " . "value=\"{$pTenderName}\" /></td>"; $ret .= "<td><input type=text size=1 id=tenderkeycap maxlength=10 " . "value=\"{$pTenderKeyCap}\" /></td>"; $ret .= "<td>{$inputRet}</td>"; $ret .= "<td colspan=1> </td>"; $ret .= "</tr>"; /* Third row of headings. */ $ret .= "<tr class='vBottom'>"; $ret .= "<th colspan=1>Input/Payment<br />Department{$hb['paymentid']['a']}</th>"; $ret .= "<th colspan=1>Input/Payment<br />Department Name{$hb['paymentname']['a']}</th>"; $ret .= "<th colspan=1>Department Keycap{$hb['paymentkeycap']['a']}</th>"; $ret .= "<th colspan=2><br />Banker{$hb['bankid']['a']}</th>"; $ret .= "</tr>"; /* Third row of inputs. */ $ret .= "<tr class='vTop'>"; $ret .= "<td>{$departmentRet}</td>"; $ret .= "<td><input type=text size=22 maxlength=25 id=paymentname " . "value=\"{$pPaymentName}\" /></td>"; $ret .= "<td><input type=text size=1 id=paymentkeycap maxlength=10 " . "value=\"{$pPaymentKeyCap}\" /></td>"; $ret .= "<td colspan=2>{$bankerRet}</td>"; $ret .= "</tr>"; /* Fourth row of headings. */ $ret .= "<tr class='vTop'>"; $ret .= "<th colspan=1>Credit OK{$hb['creditok']['a']}</th>"; $ret .= "<th colspan=1>Maximum Credit{$hb['maxcredit']['a']}</th>"; $ret .= "<th colspan=1>Input OK{$hb['inputok']['a']}</th>"; $ret .= "<th colspan=1>Transfer OK{$hb['transferok']['a']}</th>"; $ret .= "<th colspan=1> </th>"; $ret .= "</tr>"; /* Fourth row of inputs. */ $ret .= "<tr class='vTop'>"; $ret .= "<td class='iCenter'><input type=checkbox id=creditok " . ($pCreditOK == 1 ? 'checked' : '') . " /></td>"; $ret .= sprintf("<td>\$ <input type=text size=5 id=maxcredit value=\"%.2f\" /></td>", $pMaxCreditBalance); $ret .= "<td class='iCenter'><input type=checkbox id=inputok " . ($pInputOK == 1 ? 'checked' : '') . " /></td>"; $ret .= "<td class='iCenter'><input type=checkbox id=transferok " . ($pTransferOK == 1 ? 'checked' : '') . " /></td>"; $ret .= "<td colspan=1> </td>"; $ret .= "</tr>"; $ret .= "</table>"; /* Place for long help messages. * Each in its own fieldset or possibly other container. * Revealed when 2nd-level help is clicked; hidden when clicked again. */ foreach ($hbKeys as $hbKey) { if (isset($hbLongMessage["{$hbKey}"]) && $hbLongMessage["{$hbKey}"] != "") { $ret .= $hb["{$hbKey}"]['t']; } } // Remember that these are also in JS. if ($id == -1) { $ret .= "<input type=hidden id=isnew value=1 />"; } else { $ret .= "<input type=hidden id=isnew value=0 />"; // id must be the same as in the form, the <select> of programs. $ret .= "<input type=hidden id=progno value=\"{$id}\" />"; $ret .= "<input type=hidden id='origdepartment' value=\"{$pPaymentDepartment}\" />"; $ret .= "<input type=hidden id='origtender' value=\"{$pTenderType}\" />"; } /* The onclick= is what happens instead of <form action=> in * regular form submissions. */ $ret .= "<p /><input type=submit value=Save onclick=\"programSave(); return false;\" />"; echo $ret; // ajax_display_program() }