Ejemplo n.º 1
0
 /**
  * Send the reminder
  *
  * @param Texts   $texts Text object
  * @param History $hist  History
  * @param Db      $zdb   Database instance
  *
  * @return boolean
  */
 public function send($texts, $hist, $zdb)
 {
     $type_name = 'late';
     if ($this->_type === self::IMPENDING) {
         $type_name = 'impending';
     }
     if ($this->hasMail()) {
         $texts->setReplaces($this->_replaces);
         $texts->getTexts($type_name . 'duedate', $this->_dest->language);
         $mail = new GaletteMail();
         $mail->setSubject($texts->getSubject());
         $mail->setRecipients(array($this->_dest->email => $this->_dest->sname));
         $mail->setMessage($texts->getBody());
         $sent = $mail->send();
         $details = str_replace(array('%name', '%mail', '%days'), array($this->_dest->sname, $this->_dest->email, $this->_dest->days_remaining), _T("%name <%mail> (%days days)"));
         if ($sent == GaletteMail::MAIL_SENT) {
             $this->_success = true;
             $msg = '';
             if ($type_name == 'late') {
                 $msg = _T("Sent reminder mail for late membership");
             } else {
                 $msg = _T("Sent reminder mail for impending membership");
             }
             $this->_msg = $details;
             $hist->add($msg, $details);
         } else {
             $this->_success = false;
             if ($type_name == 'late') {
                 $msg = _T("A problem happened while sending late membership mail");
             } else {
                 $msg = _T("A problem happened while sending impending membership mail");
             }
             $this->_msg = $details;
             $hist->add($str, $details);
         }
     } else {
         $this->_success = false;
         $this->_nomail = true;
         $str = str_replace('%membership', $type_name, _T("Unable to send %membership reminder (no mail address)."));
         $details = str_replace(array('%name', '%id', '%days'), array($this->_dest->sname, $this->_dest->id, $this->_dest->days_remaining), _T("%name (#%id - %days days)"));
         $hist->add($str, $details);
         $this->_msg = $this->_dest->sname;
     }
     //store reminder in database
     $this->_store($zdb);
     return $this->_success;
 }
Ejemplo n.º 2
0
 $insert_values = array();
 // obtain fields
 foreach ($prefs_fields as $fieldname) {
     if (isset($_POST[$fieldname])) {
         $value = trim($_POST[$fieldname]);
     } else {
         $value = "";
     }
     // now, check validity
     if ($value != '') {
         switch ($fieldname) {
             case 'pref_email':
                 if (GALETTE_MODE === 'DEMO') {
                     Analog::log('Trying to set pref_email while in DEMO.', Analog::WARNING);
                 } else {
                     if (!Core\GaletteMail::isValidEmail($value)) {
                         $error_detected[] = _T("- Non-valid E-Mail address!");
                     }
                 }
                 break;
             case 'pref_admin_login':
                 if (GALETTE_MODE === 'DEMO') {
                     Analog::log('Trying to set superadmin login while in DEMO.', Analog::WARNING);
                 } else {
                     if (strlen($value) < 4) {
                         $error_detected[] = _T("- The username must be composed of at least 4 characters!");
                     } else {
                         //check if login is already taken
                         if ($login->loginExists($value)) {
                             $error_detected[] = _T("- This username is already in use, please choose another one!");
                         }
Ejemplo n.º 3
0
 /**
  * Set mailing recipients
  *
  * @param array $members Array of Adherent objects
  *
  * @return void
  */
 public function setRecipients($members)
 {
     $m = array();
     $this->_mrecipients = array();
     $this->_unreachables = array();
     foreach ($members as $member) {
         $email = $member->email;
         //if member mail is missing but there is a parent,
         //take the parent email.
         if (!$email && $member->hasParent()) {
             $email = $member->parent->email;
         }
         if (trim($email) != '' && self::isValidEmail($email)) {
             if (!in_array($member, $this->_mrecipients)) {
                 $this->_mrecipients[] = $member;
             }
             $m[$email] = $member->sname;
         } else {
             if (!in_array($member, $this->_unreachables)) {
                 $this->_unreachables[] = $member;
             }
         }
     }
     parent::setRecipients($m);
 }
Ejemplo n.º 4
0
 /**
  * Check posted values validity
  *
  * @param array $values   All values to check, basically the $_POST array
  *                        after sending the form
  * @param array $required Array of required fields
  * @param array $disabled Array of disabled fields
  *
  * @return true|array
  */
 public function check($values, $required, $disabled)
 {
     global $zdb, $preferences;
     $errors = array();
     $fields = self::getDbFields();
     //reset company name if needeed
     if (!isset($values['is_company']) || $values['is_company'] != 1) {
         unset($values['is_company']);
         unset($values['societe_adh']);
     }
     foreach ($fields as $key) {
         //first of all, let's sanitize values
         $key = strtolower($key);
         $prop = '_' . $this->_fields[$key]['propname'];
         if (isset($values[$key])) {
             $value = trim($values[$key]);
         } else {
             switch ($key) {
                 case 'bool_admin_adh':
                 case 'bool_exempt_adh':
                 case 'bool_display_info':
                     $value = 0;
                     break;
                 case 'activite_adh':
                     //values that are setted at object instanciation
                     $value = true;
                     break;
                 case 'date_crea_adh':
                 case 'sexe_adh':
                 case 'titre_adh':
                 case 'id_statut':
                 case 'pref_lang':
                 case 'parent_id':
                     //values that are setted at object instanciation
                     $value = $this->{$prop};
                     break;
                 default:
                     $value = '';
             }
         }
         // if the field is enabled, check it
         if (!isset($disabled[$key])) {
             // fill up the adherent structure
             if ($value !== null) {
                 $this->{$prop} = stripslashes($value);
             }
             // now, check validity
             if ($value !== null && $value != '') {
                 switch ($key) {
                     // dates
                     case 'date_crea_adh':
                     case 'ddn_adh':
                         try {
                             $d = \DateTime::createFromFormat(_T("Y-m-d"), $value);
                             if ($d === false) {
                                 //try with non localized date
                                 $d = \DateTime::createFromFormat("Y-m-d", $value);
                                 if ($d === false) {
                                     throw new \Exception('Incorrect format');
                                 }
                             }
                             $this->{$prop} = $d->format('Y-m-d');
                         } catch (\Exception $e) {
                             Analog::log('Wrong date format. field: ' . $key . ', value: ' . $value . ', expected fmt: ' . _T("Y-m-d") . ' | ' . $e->getMessage(), Analog::INFO);
                             $errors[] = str_replace(array('%date_format', '%field'), array(_T("Y-m-d"), $this->_fields[$key]['label']), _T("- Wrong date format (%date_format) for %field!"));
                         }
                         break;
                     case 'titre_adh':
                         if ($value !== null && $value !== '') {
                             if ($value == '-1') {
                                 $this->{$prop} = null;
                             } else {
                                 $this->{$prop} = new Title((int) $value);
                             }
                         } else {
                             $this->{$prop} = null;
                         }
                         break;
                     case 'email_adh':
                     case 'msn_adh':
                         if (!GaletteMail::isValidEmail($value)) {
                             $errors[] = _T("- Non-valid E-Mail address!") . ' (' . $this->getFieldName($key) . ')';
                         }
                         if ($key == 'email_adh') {
                             try {
                                 $select = $zdb->select(self::TABLE);
                                 $select->columns(array(self::PK))->where(array('email_adh' => $value));
                                 if ($this->_id != '' && $this->_id != null) {
                                     $select->where(self::PK . ' != ' . $this->_id);
                                 }
                                 $results = $zdb->execute($select);
                                 if ($results->count() !== 0) {
                                     $errors[] = _T("- This E-Mail address is already used by another member!");
                                 }
                             } catch (\Exception $e) {
                                 Analog::log('An error occured checking member email unicity.', Analog::ERROR);
                                 $errors[] = _T("An error has occured while looking if login already exists.");
                             }
                         }
                         break;
                     case 'url_adh':
                         if ($value == 'http://') {
                             $this->{$prop} = '';
                         } elseif (!isValidWebUrl($value)) {
                             $errors[] = _T("- Non-valid Website address! Maybe you've skipped the http:// ?");
                         }
                         break;
                     case 'login_adh':
                         /** FIXME: add a preference for login lenght */
                         if (strlen($value) < 2) {
                             $errors[] = str_replace('%i', 2, _T("- The username must be composed of at least %i characters!"));
                         } else {
                             //check if login does not contain the @ character
                             if (strpos($value, '@') != false) {
                                 $errors[] = _T("- The username cannot contain the @ character");
                             } else {
                                 //check if login is already taken
                                 try {
                                     $select = $zdb->select(self::TABLE);
                                     $select->columns(array(self::PK))->where(array('login_adh' => $value));
                                     if ($this->_id != '' && $this->_id != null) {
                                         $select->where(self::PK . ' != ' . $this->_id);
                                     }
                                     $results = $zdb->execute($select);
                                     if ($results->count() !== 0 || $value == $preferences->pref_admin_login) {
                                         $errors[] = _T("- This username is already in use, please choose another one!");
                                     }
                                 } catch (\Exception $e) {
                                     Analog::log('An error occured checking member login unicity.', Analog::ERROR);
                                     $errors[] = _T("An error has occured while looking if login already exists.");
                                 }
                             }
                         }
                         break;
                     case 'mdp_adh':
                         /** TODO: check password complexity, set by a preference */
                         /** FIXME: add a preference for password lenght */
                         if (strlen($value) < 6) {
                             $errors[] = str_replace('%i', 6, _T("- The password must be of at least %i characters!"));
                         } else {
                             if ($this->_self_adh !== true && (!isset($values['mdp_adh2']) || $values['mdp_adh2'] != $value)) {
                                 $errors[] = _T("- The passwords don't match!");
                             } else {
                                 if ($this->_self_adh === true && !crypt($value, $values['mdp_crypt']) == $values['mdp_crypt']) {
                                     $errors[] = _T("Password misrepeated: ");
                                 } else {
                                     $this->{$prop} = password_hash($value, PASSWORD_BCRYPT);
                                 }
                             }
                         }
                         break;
                     case 'id_statut':
                         try {
                             //check if status exists
                             $select = $zdb->select(Status::TABLE);
                             $select->where(Status::PK . '= ' . $value);
                             $results = $zdb->execute($select);
                             $result = $results->current();
                             if ($result === false) {
                                 $errors[] = str_replace('%id', $value, _T("Status #%id does not exists in database."));
                                 break;
                             }
                             //check for status unicity
                             $select = $zdb->select(self::TABLE, 'a');
                             $select->limit(1)->join(array('b' => PREFIX_DB . Status::TABLE), 'a.' . Status::PK . '=b.' . Status::PK, array('libelle_statut'))->where('b.' . Status::PK . '=' . $value);
                             $select->where->lessThan('b.priorite_statut', Members::NON_STAFF_MEMBERS);
                             if ($this->_id != '' && $this->_id != null) {
                                 $select->where('a.' . self::PK . ' != ' . $this->_id);
                             }
                             $results = $zdb->execute($select);
                             $result = $results->current();
                             if ($result !== false) {
                                 $errors[] = str_replace(array('%s', '%i', '%n', '%m'), array($result->libelle_statut, $result->id_adh, $result->nom_adh, $result->prenom_adh), _T("Selected status (%s) is already in use in <a href='voir_adherent.php?id_adh=%i'>%n %m's profile</a>."));
                             }
                         } catch (\Exception $e) {
                             Analog::log('An error occured checking status unicity: ' . $e->getMessage(), Analog::ERROR);
                             $errors[] = _T("An error has occured while looking if status is already in use.");
                         }
                         break;
                 }
             } else {
                 if ($key == 'login_adh' && !isset($required['login_adh']) || $key == 'mdp_adh' && !isset($required['mdp_adh']) && !isset($this->_id)) {
                     $p = new Password();
                     $this->{$prop} = $p->makeRandomPassword(15);
                 }
             }
         }
     }
     // missing required fields?
     while (list($key, $val) = each($required)) {
         $prop = '_' . $this->_fields[$key]['propname'];
         if (isset($disabled[$key])) {
             $mandatory_missing = false;
             if (!isset($this->{$prop})) {
                 $mandatory_missing = true;
             } else {
                 if ($key === 'titre_adh' && $this->{$prop} == '-1') {
                     $mandatory_missing = true;
                 }
             }
             if ($mandatory_missing === true) {
                 $errors[] = _T("- Mandatory field empty: ") . ' <a href="#' . $key . '">' . $this->getFieldName($key) . '</a>';
             }
         }
     }
     //attach to/detach from parent
     if (isset($values['detach_parent'])) {
         $this->_parent = null;
     }
     if (count($errors) > 0) {
         Analog::log('Some errors has been throwed attempting to edit/store a member' . print_r($errors, true), Analog::DEBUG);
         return $errors;
     } else {
         Analog::log('Member checked successfully.', Analog::DEBUG);
         return true;
     }
 }
Ejemplo n.º 5
0
         }
     } else {
         $txt = preg_replace(array('/%name/', '/%email/'), array($adh->sname, $adh->email), _T("Trying to send a mail to a member (%name) with an invalid address: %email"));
         $hist->add($txt);
         $warning_detected[] = $txt;
     }
 }
 // Sent email to admin if pref checked
 if ($new && $preferences->pref_bool_mailadh) {
     // Get email text in database
     $text = 'newcont';
     if (!$contrib->isCotis()) {
         $text = 'newdonation';
     }
     $mtxt = $texts->getTexts($text, $preferences->pref_lang);
     $mail = new GaletteMail();
     $mail->setSubject($texts->getSubject());
     /** TODO: only super-admin is contacted here. We should send
      *  a message to all admins, or propose them a chekbox if
      *  they don't want to get bored
      */
     $mail->setRecipients(array($preferences->pref_email_newadh => str_replace('%asso', $preferences->pref_name, _T("%asso Galette's admin"))));
     $mail->setMessage($texts->getBody());
     $sent = $mail->send();
     if ($sent) {
         $hist->add(preg_replace(array('/%name/', '/%email/'), array($adh->sname, $adh->email), _T("Mail sent to admin for user %name (%email)")));
     } else {
         $txt = preg_replace(array('/%name/', '/%email/'), array($adh->sname, $adh->email), _T("A problem happened while sending to admin notification for user %name (%email) contribution"));
         $hist->add($txt);
         $error_detected[] = $txt;
     }
Ejemplo n.º 6
0
     if ($sent == GaletteMail::MAIL_SENT) {
         $hist->add(str_replace('%s', $member->sname . ' (' . $member->email . ')', _T("New account mail sent to admin for '%s'.")));
     } else {
         $str = str_replace('%s', $member->sname . ' (' . $member->email . ')', _T("A problem happened while sending email to admin for account '%s'."));
         $hist->add($str);
         $error_detected[] = $str;
     }
     unset($texts);
 }
 // send mail to member
 if ($preferences->pref_mail_method > GaletteMail::METHOD_DISABLED && $member->email != '') {
     //send mail to member
     // Get email text in database
     $texts = new Texts($texts_fields, $preferences, array('name_adh' => custom_html_entity_decode($member->sname), 'firstname_adh' => custom_html_entity_decode($member->surname), 'lastname_adh' => custom_html_entity_decode($member->name), 'mail_adh' => custom_html_entity_decode($member->email), 'login_adh' => custom_html_entity_decode($member->login), 'password_adh' => custom_html_entity_decode($_POST['mdp_adh'])));
     $mtxt = $texts->getTexts('sub', $member->language);
     $mail = new GaletteMail();
     $mail->setSubject($texts->getSubject());
     $mail->setRecipients(array($member->email => $member->sname));
     $mail->setMessage($texts->getBody());
     $sent = $mail->send();
     if ($sent == GaletteMail::MAIL_SENT) {
         $hist->add(str_replace('%s', $member->sname . ' (' . $member->email . ')', _T("New account mail sent to '%s'.")));
     } else {
         $str = str_replace('%s', $member->sname . ' (' . $member->email . ')', _T("A problem happened while sending new account mail to '%s'"));
         $hist->add($str);
         $error_detected[] = $str;
     }
 }
 /** FIXME: query was previously passed as second argument,
  * but it not no longer available from here :/ */
 $hist->add(_T("Self_subscription as a member: ") . strtoupper($adherent['nom_adh']) . ' ' . $adherent['prenom_adh']);