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() }
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() }
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() }