Пример #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()
 }