Exemple #1
0
 /**
  * Get the entire mailings list
  *
  * @return array
  */
 public function getMailingHistory()
 {
     global $zdb;
     if ($this->counter == null) {
         $c = $this->getCount();
         if ($c == 0) {
             Analog::log('No entry in history (yet?).', Analog::DEBUG);
             return;
         } else {
             $this->counter = (int) $c;
             $this->countPages();
         }
     }
     try {
         $select = $zdb->select($this->getTableName(), 'a');
         $select->join(array('b' => PREFIX_DB . Adherent::TABLE), 'a.mailing_sender=b.' . Adherent::PK, array('nom_adh', 'prenom_adh'), $select::JOIN_LEFT)->order($this->orderby . ' ' . $this->ordered);
         //add limits to retrieve only relavant rows
         $this->setLimits($select);
         $results = $zdb->execute($select);
         $ret = array();
         foreach ($results as $r) {
             if ($r['mailing_sender'] !== null) {
                 $r['mailing_sender_name'] = Adherent::getSName($r['mailing_sender']);
             }
             $body_resume = $r['mailing_body'];
             if (strlen($body_resume) > 150) {
                 $body_resume = substr($body_resume, 0, 150);
                 $body_resume .= '[...]';
             }
             if (function_exists('tidy_parse_string')) {
                 //if tidy extension is present, we use it to clean a bit
                 $tidy_config = array('clean' => true, 'show-body-only' => true, 'wrap' => 0);
                 $tidy = tidy_parse_string($body_resume, $tidy_config, 'UTF8');
                 $tidy->cleanRepair();
                 $r['mailing_body_resume'] = tidy_get_output($tidy);
             } else {
                 //if it is not... Well, let's serve the text as it.
                 $r['mailing_body_resume'] = $body_resume;
             }
             $attachments = 0;
             if (file_exists(GALETTE_ATTACHMENTS_PATH . $r[self::PK])) {
                 $rdi = new \RecursiveDirectoryIterator(GALETTE_ATTACHMENTS_PATH . $r[self::PK], \FilesystemIterator::SKIP_DOTS);
                 $contents = new \RecursiveIteratorIterator($rdi, \RecursiveIteratorIterator::CHILD_FIRST);
                 foreach ($contents as $path) {
                     if ($path->isFile()) {
                         $attachments++;
                     }
                 }
             }
             $r['attachments'] = $attachments;
             $ret[] = $r;
         }
         return $ret;
     } catch (\Exception $e) {
         Analog::log('Unable to get history. | ' . $e->getMessage(), Analog::WARNING);
         return false;
     }
 }
Exemple #2
0
 /**
  * Store the transaction
  *
  * @return boolean
  */
 public function store()
 {
     global $zdb, $hist;
     try {
         $zdb->connection->beginTransaction();
         $values = array();
         $fields = self::getDbFields();
         /** FIXME: quote? */
         foreach ($fields as $field) {
             $prop = '_' . $this->_fields[$field]['propname'];
             $values[$field] = $this->{$prop};
         }
         if (!isset($this->_id) || $this->_id == '') {
             //we're inserting a new transaction
             unset($values[self::PK]);
             $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 . 'transactions_id_seq');
                 } else {
                     $this->_id = $zdb->driver->getLastGeneratedValue();
                 }
                 // logging
                 $hist->add(_T("Transaction added"), Adherent::getSName($this->_member));
             } else {
                 $hist->add(_T("Fail to add new transaction."));
                 throw new \Exception('An error occured inserting new transaction!');
             }
         } else {
             //we're editing an existing transaction
             $update = $zdb->update(self::TABLE);
             $update->set($values)->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) {
                 $hist->add(_T("Transaction updated"), Adherent::getSName($this->_member));
             }
         }
         $zdb->connection->commit();
         return true;
     } catch (\Exception $e) {
         $zdb->connection->rollBack();
         Analog::log('Something went wrong :\'( | ' . $e->getMessage() . "\n" . $e->getTraceAsString(), Analog::ERROR);
         return false;
     }
 }
Exemple #3
0
 /**
  * Store the contribution
  *
  * @return boolean
  */
 public function store()
 {
     global $zdb, $hist;
     try {
         $zdb->connection->beginTransaction();
         $values = array();
         $fields = self::getDbFields();
         foreach ($fields as $field) {
             $prop = '_' . $this->_fields[$field]['propname'];
             switch ($field) {
                 case ContributionsTypes::PK:
                 case Transaction::PK:
                     if (isset($this->{$prop})) {
                         $values[$field] = $this->{$prop}->id;
                     }
                     break;
                 default:
                     $values[$field] = $this->{$prop};
                     break;
             }
         }
         //no end date, let's take database defaults
         if (!$this->isCotis() && !$this->_end_date) {
             unset($values['date_fin_cotis']);
         }
         if (!isset($this->_id) || $this->_id == '') {
             //we're inserting a new contribution
             unset($values[self::PK]);
             $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 . 'cotisations_id_seq');
                 } else {
                     $this->_id = $zdb->driver->getLastGeneratedValue();
                 }
                 // logging
                 $hist->add(_T("Contribution added"), Adherent::getSName($this->_member));
             } else {
                 $hist->add(_T("Fail to add new contribution."));
                 throw new \Exception('An error occured inserting new contribution!');
             }
         } else {
             //we're editing an existing contribution
             $update = $zdb->update(self::TABLE);
             $update->set($values)->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) {
                 $hist->add(_T("Contribution updated"), Adherent::getSName($this->_member));
             } else {
                 if ($edit === false) {
                     throw new \Exception('An error occured updating contribution # ' . $this->_id . '!');
                 }
             }
         }
         //update deadline
         if ($this->isCotis()) {
             $deadline = $this->_updateDeadline();
             if ($deadline !== true) {
                 //if something went wrong, we rollback transaction
                 throw new \Exception('An error occured updating member\'s deadline');
             }
         }
         $zdb->connection->commit();
         $this->_orig_amount = $this->_amount;
         return true;
     } catch (\Exception $e) {
         $zdb->connection->rollBack();
         Analog::log('Something went wrong :\'( | ' . $e->getMessage() . "\n" . $e->getTraceAsString(), Analog::ERROR);
         return false;
     }
 }
Exemple #4
0
        if ($m['id_adh'] == $member->id) {
            $navigate = array('cur' => $m['id_adh'], 'count' => count($ids), 'pos' => $k + 1);
            if ($k > 0) {
                $navigate['prev'] = $ids[$k - 1]['id_adh'];
            }
            if ($k < count($ids) - 1) {
                $navigate['next'] = $ids[$k + 1]['id_adh'];
            }
            break;
        }
    }
}
$children = array();
if ($member->hasChildren()) {
    foreach ($member->children as $child) {
        $children[$child] = Adherent::getSName($child);
    }
}
// Set caller page ref for cards error reporting
$session['caller'] = 'voir_adherent.php?id_adh=' . $id_adh;
// declare dynamic field values
$adherent['dyn'] = $dyn_fields->getFields('adh', $id_adh, true);
// - declare dynamic fields for display
$disabled['dyn'] = array();
$dynamic_fields = $dyn_fields->prepareForDisplay('adh', $adherent['dyn'], $disabled['dyn'], 0);
if (isset($error_detected)) {
    $tpl->assign('error_detected', $error_detected);
}
$tpl->assign('page_title', _T("Member Profile"));
$tpl->assign('require_dialog', true);
$tpl->assign('member', $member);