Esempio n. 1
0
 /**
  * Store the member
  *
  * @return boolean
  */
 public function store()
 {
     global $zdb, $hist;
     try {
         $values = array();
         $fields = self::getDbFields();
         /** FIXME: quote? */
         foreach ($fields as $field) {
             if ($field !== 'date_modif_adh' || !isset($this->_id) || $this->_id == '') {
                 $prop = '_' . $this->_fields[$field]['propname'];
                 if (($field === 'bool_admin_adh' || $field === 'bool_exempt_adh' || $field === 'bool_display_info') && $this->{$prop} === false) {
                     //Handle booleans for postgres ; bugs #18899 and #19354
                     $values[$field] = 'false';
                 } elseif ($field === 'parent_id') {
                     //handle parents
                     if ($this->_parent === null) {
                         $values['parent_id'] = new Expression('NULL');
                     } elseif ($this->parent instanceof Adherent) {
                         $values['parent_id'] = $this->_parent->id;
                     } else {
                         $values['parent_id'] = $this->_parent;
                     }
                 } else {
                     $values[$field] = $this->{$prop};
                 }
             }
         }
         //an empty value will cause date to be set to 1901-01-01, a null
         //will result in 0000-00-00. We want a database NULL value here.
         if (!$this->_birthdate) {
             $values['ddn_adh'] = new Expression('NULL');
         }
         if (!$this->_due_date) {
             $values['date_echeance'] = new Expression('NULL');
         }
         if ($this->_title instanceof Title) {
             $values['titre_adh'] = $this->_title->id;
         } else {
             $values['titre_adh'] = new Expression('NULL');
         }
         if (!$this->_parent) {
             $values['parent_id'] = new Expression('NULL');
         }
         if (!isset($this->_id) || $this->_id == '') {
             //we're inserting a new member
             unset($values[self::PK]);
             //set modification date
             $this->_modification_date = date('Y-m-d');
             $values['date_modif_adh'] = $this->_modification_date;
             $insert = $zdb->insert(self::TABLE);
             $insert->values($values);
             $add = $zdb->execute($insert);
             if ($add->count() > 0) {
                 if ($zdb->isPostgres()) {
                     $this->_id = $zdb->driver->getLastGeneratedValue(PREFIX_DB . 'adherents_id_seq');
                 } else {
                     $this->_id = $zdb->driver->getLastGeneratedValue();
                 }
                 $this->_picture = new Picture($this->_id);
                 // logging
                 $hist->add(_T("Member card added"), strtoupper($this->_login));
                 return true;
             } else {
                 $hist->add(_T("Fail to add new member."));
                 throw new \Exception('An error occured inserting new member!');
             }
         } else {
             //we're editing an existing member
             if (!$this->isDueFree()) {
                 // deadline
                 $due_date = Contribution::getDueDate($this->_id);
                 if ($due_date) {
                     $values['date_echeance'] = $due_date;
                 }
             }
             if (!$this->_password) {
                 unset($values['mdp_adh']);
             }
             $update = $zdb->update(self::TABLE);
             $update->set($values);
             $update->where(self::PK . '=' . $this->_id);
             $edit = $zdb->execute($update);
             //edit == 0 does not mean there were an error, but that there
             //were nothing to change
             if ($edit->count() > 0) {
                 $this->_updateModificationDate();
                 $hist->add(_T("Member card updated"), strtoupper($this->_login));
             }
             return true;
         }
         //DEBUG
         return false;
     } catch (\Exception $e) {
         Analog::log('Something went wrong :\'( | ' . $e->getMessage() . "\n" . $e->getTraceAsString(), Analog::ERROR);
         return false;
     }
 }
Esempio n. 2
0
        if ($id_cotis != '') {
            $contrib = new Contribution((int) $id_cotis);
            if ($contrib->id == '') {
                //not possible to load contribution, exit
                header('location: index.php');
                die;
            }
        } else {
            $args = array('type' => $selected_type, 'adh' => $id_adh);
            if ($trans_id != '') {
                $args['trans'] = $trans_id;
            }
            if ($preferences->pref_membership_ext != '') {
                $args['ext'] = $preferences->pref_membership_ext;
            }
            $contrib = new Contribution($args);
            if ($contrib->isTransactionPart()) {
                $id_adh = $contrib->member;
                //Should we disable contribution member selection if we're from
                //a transaction? In most cases, it would be OK I guess, but I'm
                //very unsure
                //$disabled['id_adh'] = ' disabled="disabled"';
            }
        }
        //second step only: first step, and all the rest
        // flagging required fields for second step
        $second_required = array('montant_cotis' => 1, 'date_debut_cotis' => 1, 'date_fin_cotis' => $contrib->isCotis());
        $required = $required + $second_required;
    }
}
// Validation
Esempio n. 3
0
 /**
  * Detach a contribution from a transaction
  *
  * @param int $trans_id   Transaction identifier
  * @param int $contrib_id Contribution identifier
  *
  * @return boolean
  */
 public static function unsetTransactionPart($trans_id, $contrib_id)
 {
     global $zdb;
     try {
         //first, we check if contribution is part of transaction
         $c = new Contribution((int) $contrib_id);
         if ($c->isTransactionPartOf($trans_id)) {
             $update = $zdb->update(self::TABLE);
             $update->set(array(Transaction::PK => null))->where(self::PK . ' = ' . $contrib_id);
             $zdb->execute($update);
             return true;
         } else {
             Analog::log('Contribution #' . $contrib_id . ' is not actually part of transaction #' . $trans_id, Analog::WARNING);
             return false;
         }
     } catch (\Exception $e) {
         Analog::log('Unable to detach contribution #' . $contrib_id . ' to transaction #' . $trans_id . ' | ' . $e->getMessage(), Analog::ERROR);
         return false;
     }
 }
Esempio n. 4
0
$transaction['trans_amount'] = get_numeric_form_value("trans_amount", '');
$transaction['trans_date'] = get_form_value("trans_date", '');
$transaction['trans_desc'] = get_form_value("trans_desc", '');
$transaction['id_adh'] = get_numeric_form_value("id_adh", '');
// flagging required fields
$required = array('trans_amount' => 1, 'trans_date' => 1, 'trans_desc' => 1, 'id_adh' => 1);
$disabled = array();
if (isset($_GET['detach'])) {
    if (!Contribution::unsetTransactionPart($trans_id, $_GET['detach'])) {
        $error_detected[] = _T("Unable to detach contribution from transaction");
    } else {
        $success_detected[] = _T("Contribution has been successfully detached from current transaction");
    }
}
if (isset($_GET['cid']) && $_GET['cid'] != null) {
    if (!Contribution::setTransactionPart($trans_id, $_GET['cid'])) {
        $error_detected[] = _T("Unable to attach contribution to transaction");
    } else {
        $success_detected[] = _T("Contribution has been successfully attached to current transaction");
    }
}
if ($trans_id != '') {
    // initialize transactions structure with database values
    $trans->load($trans_id);
    if ($trans->id == '') {
        //not possible to load transaction, exit
        header('location: index.php');
        die;
    }
}
// Validation
Esempio n. 5
0
 /**
  * Remove specified contributions
  *
  * @param integer|array $ids         Contributions identifiers to delete
  * @param boolean       $transaction True to begin a database transaction
  *
  * @return boolean
  */
 public function removeContributions($ids, $transaction = true)
 {
     global $zdb, $hist;
     $list = array();
     if (is_numeric($ids)) {
         //we've got only one identifier
         $list[] = $ids;
     } else {
         $list = $ids;
     }
     if (is_array($list)) {
         $res = true;
         try {
             if ($transaction) {
                 $zdb->connection->beginTransaction();
             }
             $select = $zdb->select(self::TABLE);
             $select->where->in(self::PK, $list);
             $contributions = $zdb->execute($select);
             foreach ($contributions as $contribution) {
                 $c = new Contribution($contribution);
                 $res = $c->remove(false);
                 if ($res === false) {
                     throw new \Exception();
                 }
             }
             if ($transaction) {
                 $zdb->connection->commit();
             }
             $hist->add(str_replace('%list', print_r($list, true), _T("Contributions deleted (%list)")));
         } catch (\Exception $e) {
             if ($transaction) {
                 $zdb->connection->rollBack();
             }
             Analog::log('An error occured trying to remove contributions | ' . $e->getMessage(), Analog::ERROR);
             return false;
         }
     } else {
         //not numeric and not an array: incorrect.
         Analog::log('Asking to remove contribution, but without providing an array or a single numeric value.', Analog::WARNING);
         return false;
     }
 }