/** * Store members in database * * @param string $filename CSV filename * * @return boolean */ private function _storeMembers($filename) { $handle = fopen(self::DEFAULT_DIRECTORY . '/' . $filename, 'r'); $row = 0; try { while (($data = fgetcsv($handle, 1000, self::DEFAULT_SEPARATOR, self::DEFAULT_QUOTE)) !== false) { if ($row > 0) { $col = 0; $values = array(); foreach ($data as $column) { $values[$this->_fields[$col]] = $column; if ($this->_fields[$col] === 'societe_adh') { $values['is_company'] = true; } $col++; } //import member itself $member = new Adherent(); //check for empty creation date if (isset($values['date_crea_adh']) && trim($values['date_crea_adh']) === '') { unset($values['date_crea_adh']); } $valid = $member->check($values, $this->_required, null); if ($valid === true) { if ($this->_dryrun === false) { $store = $member->store(); if ($store !== true) { $this->addError(str_replace(array('%row', '%name'), array($row, $member->sname), _T("An error occured storing member at row %row (%name):"))); return false; } } } else { $this->addError(str_replace(array('%row', '%name'), array($row, $member->sname), _T("An error occured storing member at row %row (%name):"))); if (is_array($valid)) { foreach ($valid as $e) { $this->addError($e); } } return false; } } $row++; } return true; } catch (\Exception $e) { $this->addError($e->getMessage()); } return false; }
*/ use Galette\Core\GaletteMail; use Galette\Entity\DynamicFields; use Galette\Entity\Adherent; use Galette\Entity\FieldsConfig; use Galette\Entity\Texts; use Galette\Repository\Titles; use Galette\Core\PasswordImage; /** @ignore */ require_once 'includes/galette.inc.php'; if (!$preferences->pref_bool_selfsubscribe) { header('location:index.php'); die; } $dyn_fields = new DynamicFields(); $member = new Adherent(); //mark as self membership $member->setSelfMembership(); // flagging required fields $fc = new FieldsConfig(Adherent::TABLE, $members_fields, $members_fields_cats); // flagging required fields invisible to members $fc->setNotRequired('activite_adh'); $fc->setNotRequired('id_statut'); $required = $fc->getRequired(); // flagging fields visibility $visibles = $fc->getVisibilities(); // disable some fields $disabled = $member->disabled_fields; // DEBUT parametrage des champs // On recupere de la base la longueur et les flags des champs // et on initialise des valeurs par defaut
//Mails are disabled... We log (not safe, but)... Analog::log('Post contribution script has failed. Here was the data: ' . "\n" . print_r($res, true), Analog::ERROR); } } } } } else { //something went wrong :'( $error_detected[] = _T("An error occured while storing the contribution."); } } } if (count($error_detected) == 0) { $dyn_fields->setAllFields('contrib', $contrib->id, $contribution['dyn']); // Get member informations $adh = new Adherent(); $adh->load($contrib->member); if ($preferences->pref_mail_method > GaletteMail::METHOD_DISABLED) { $texts = new Texts($texts_fields, $preferences, array('name_adh' => custom_html_entity_decode($adh->sname), 'firstname_adh' => custom_html_entity_decode($adh->surname), 'lastname_adh' => custom_html_entity_decode($adh->name), 'mail_adh' => custom_html_entity_decode($adh->email), 'login_adh' => custom_html_entity_decode($adh->login), 'deadline' => custom_html_entity_decode($contrib->end_date), 'contrib_info' => custom_html_entity_decode($contrib->info), 'contrib_amount' => custom_html_entity_decode($contrib->amount), 'contrib_type' => custom_html_entity_decode($contrib->type->libelle))); if ($new && isset($_POST['mail_confirm']) && $_POST['mail_confirm'] == '1') { if (GaletteMail::isValidEmail($adh->email)) { $text = 'contrib'; if (!$contrib->isCotis()) { $text = 'donation'; } $mtxt = $texts->getTexts($text, $adh->language); $mail = new GaletteMail(); $mail->setSubject($texts->getSubject()); $mail->setRecipients(array($adh->email => $adh->sname)); $mail->setMessage($texts->getBody()); $sent = $mail->send();
use Galette\Entity\Adherent; use Galette\Entity\FieldsConfig; use Galette\Entity\Texts; use Galette\Entity\DynamicFields; use Galette\Repository\Members; use Galette\Repository\Titles; use Galette\Repository\Groups; use Galette\Filters\MembersList; /** @ignore */ require_once 'includes/galette.inc.php'; if (!$login->isLogged()) { header('location: index.php'); die; } $deps = array('picture' => true, 'groups' => true, 'dues' => true, 'parent' => true, 'children' => true); $member = new Adherent(null, $deps); //TODO: dynamic fields should be handled by Adherent object $dyn_fields = new DynamicFields(); // new or edit $adherent['id_adh'] = get_numeric_form_value('id_adh', ''); if ($login->isAdmin() || $login->isStaff() || $login->isGroupManager()) { $adherent['id_adh'] = get_numeric_form_value('id_adh', ''); if ($adherent['id_adh']) { $member->load($adherent['id_adh']); if (!$login->isAdmin() && !$login->isStaff() && $login->isGroupManager()) { //check if current logged in user can manage loaded member $groups = $member->groups; $can_manage = false; foreach ($groups as $group) { if ($login->isGroupManager($group->getId())) { $can_manage = true;
/** * 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; } }
/** * Execute post contribution script * * @param ExternalScript $es External script to execute * @param array $extra Extra informations on contribution * Defaults to null * @param array $pextra Extra information on payment * Defaults to null * * @return mixed Script return value on success, values and script output on fail */ public function executePostScript(ExternalScript $es, $extra = null, $pextra = null) { global $zdb, $preferences; $payment = array('type' => $this->getPaymentType()); if ($pextra !== null && is_array($pextra)) { $payment = array_merge($payment, $pextra); } if (!file_exists(GALETTE_CACHE_DIR . '/pdf_contribs')) { @mkdir(GALETTE_CACHE_DIR . '/pdf_contribs'); } $voucher_path = null; if ($this->_id !== null) { $voucher = new PdfContribution($this, $zdb, $preferences); $voucher->store(GALETTE_CACHE_DIR . '/pdf_contribs'); $voucher_path = $voucher->getPath(); } $contrib = array('date' => $this->_date, 'type' => $this->getRawType(), 'amount' => $this->amount, 'voucher' => $voucher_path, 'category' => array('id' => $this->type->id, 'label' => $this->type->libelle), 'payment' => $payment); if ($this->_member !== null) { $m = new Adherent((int) $this->_member); $member = array('name' => $m->sfullname, 'email' => $m->email, 'organization' => $m->isCompany() ? 1 : 0, 'status' => array('id' => $m->status, 'label' => $m->sstatus), 'country' => $m->country); if ($m->isCompany()) { $member['organization_name'] = $m->company_name; } $contrib['member'] = $member; } if ($extra !== null && is_array($extra)) { $contrib = array_merge($contrib, $extra); } $res = $es->send($contrib); if ($res !== true) { Analog::log('An error occured calling post contribution ' . "script:\n" . $es->getOutput(), Analog::ERROR); $res = _T("Contribution informations") . "\n"; $res .= print_r($contrib, true); $res .= "\n\n" . _T("Script output") . "\n"; $res .= $es->getOutput(); } return $res; }
/** * 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; } }
if (isset($session['pdf_error']) && $session['pdf_error']) { $error_detected[] = $session['pdf_error_msg']; unset($session['pdf_error_msg']); unset($session['pdf_error']); } if (isset($session['lostpasswd_errors'])) { $error_detected = unserialize($session['lostpasswd_errors']); unset($session['lostpasswd_errors']); } if (isset($session['lostpasswd_success'])) { $success_detected = unserialize($session['lostpasswd_success']); unset($session['lostpasswd_success']); } $dyn_fields = new DynamicFields(); $deps = array('picture' => true, 'groups' => true, 'dues' => true, 'parent' => true, 'children' => true); $member = new Adherent((int) $id_adh, $deps); // flagging fields visibility $fc = new FieldsConfig(Adherent::TABLE, $members_fields, $members_fields_cats); $visibles = $fc->getVisibilities(); if ($login->id != $id_adh && !$login->isAdmin() && !$login->isStaff()) { //check if requested member is part of managed groups $groups = $member->groups; $is_managed = false; foreach ($groups as $g) { if ($login->isGroupManager($g->getId())) { $is_managed = true; break; } } if ($is_managed !== true) { //requested member is not part of managed groups, fall back to logged