Пример #1
0
 /**
  * notify by email the user of the reception of a message
  *
  * @param array of int: $userDataList user identificatin list
  * @param MessageToSend $message message envoy�
  * @param int $messageId identification of the message
  * 
  */
 public function notify($userDataList, $message, $messageId)
 {
     if (!get_conf('mailNotification', TRUE)) {
         return;
     }
     // sender name and email
     if ($message->getSender() == 0) {
         $userData = array('mail' => get_conf('no_reply_mail') ? get_conf('no_reply_mail') : get_conf('administrator_email'), 'firstName' => get_lang('Message from %platformName', array('%platformName' => get_conf('siteName'))), 'lastName' => '');
     } else {
         $userData = claro_get_current_user_data();
     }
     //************************************ IS MANAGER
     $stringManager = false;
     $courseManagers = claro_get_course_manager_id($message->getCourseCode());
     $nbrOfManagers = count($courseManagers);
     for ($countManager = 0; $countManager < $nbrOfManagers; $countManager++) {
         if ($message->getSender() == $courseManagers[$countManager]) {
             $courseData = claro_get_course_data($message->getCourseCode());
             $stringManager = get_block('Course manager of %course%(%courseCode%)', array('%course%' => $courseData['name'], '%courseCode%' => $courseData['officialCode']));
         }
     }
     //---------------------- email subject
     $emailSubject = '[' . get_conf('siteName');
     if (!is_null($message->getCourseCode())) {
         $courseData = claro_get_course_data($message->getCourseCode());
         if ($courseData) {
             $emailSubject .= ' - ' . $courseData['officialCode'];
         }
     }
     $emailSubject .= '] ' . $message->getSubject();
     //------------------------------subject
     /* $altBody = get_lang('If you can\'t read this message go to: ') . rtrim( get_path('rootWeb'), '/' ) . '/claroline/messaging/readmessage.php?messageId=' . $messageId . '&type=received' . "\n\n"
        . '-- '
        . claro_get_current_user_data('lastName') . " " . claro_get_current_user_data('firstName') . "\n"
        . $stringManager
        . "\n\n" . get_conf('siteName') ." <" . get_conf('rootWeb') . '>' . "\n"
        . '   ' . get_lang('Administrator') . ' : ' . get_conf('administrator_name') . ' <' . get_conf('administrator_email') . '>' . "\n"
        ; */
     //-------------------------BODY
     $msgContent = claro_parse_user_text($message->getMessage());
     $urlAppend = get_path('url');
     if (!empty($urlAppend)) {
         $msgContent = preg_replace('!href="' . get_path('url') . '!', 'href="' . rtrim(get_path('rootWeb'), '/') . '/', $msgContent);
         $msgContent = preg_replace('!\\>' . get_path('url') . '!', '>' . get_path('rootWeb'), $msgContent);
     } else {
         $msgContent = preg_replace('!href="/!', 'href="' . rtrim(get_path('rootWeb'), '/') . '/', $msgContent);
     }
     $emailBody = "<html><head></head><body>" . $msgContent . '<br /><br />' . '-- <br />' . get_lang('%firstName %lastName', array('%firstName' => $userData['firstName'], '%lastName' => $userData['lastName'])) . "<br />" . $stringManager . '<br /><br /><a href="' . get_conf('rootWeb') . '">' . get_conf('siteName') . '</a><br />' . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . get_lang('Administrator') . ': <a href="mailto:' . get_conf('administrator_email') . '">' . get_conf('administrator_name') . '</a><br />' . '</body></html>';
     //******************************** END BODY
     //******************************************
     if (empty($userData['mail']) || !is_well_formed_email_address($userData['mail'])) {
         // do not send email for a user with no mail address
         pushClaroMessage('Mail Notification Failed : User has no email or an invalid one : ' . var_export($userData, true) . '!');
         return claro_failure::set_failure(get_lang("Mail Notification Failed : You don't have any email address defined in your user profile or the defined email address is not valid."));
     }
     self::emailNotification($userDataList, $emailBody, $emailSubject, $userData['mail'], get_lang('%firstName %lastName', array('%firstName' => $userData['firstName'], '%lastName' => $userData['lastName'])));
 }
Пример #2
0
 /**
  * validate email ( and semi-column separated email list )
  *
  * @return boolean success
  */
 protected function validateEmailList()
 {
     // empty email is valide as we already checked if field was required
     if (empty($this->email)) {
         return true;
     }
     $emailControlList = strtr($this->email, ', ', ';');
     $emailControlList = preg_replace('/;+/', ';', $emailControlList);
     $emailControlList = explode(';', $emailControlList);
     $emailValidList = array();
     foreach ($emailControlList as $emailControl) {
         $emailControl = trim($emailControl);
         if (!is_well_formed_email_address($emailControl)) {
             return false;
         } else {
             $emailValidList[] = $emailControl;
         }
     }
     $this->email = implode(';', $emailValidList);
     return true;
 }
Пример #3
0
/**
 * Check EMAIL SYNTHAX : if new users in Claroline with the specified parameters contains synthax error
 * in mail given.
 *
 * @author Guillaume Lederer <*****@*****.**>
 *
 * @param  $userlist must be a 2D array with the list of potential new users :
 *         $userlist['email'][$i] for the email
 *
 *
 * @return $errors : an array of boolean where $errors[$i] is TRUE if there is an error with entry $i in the given array.
 *
 *
 */
function check_email_synthax_userlist($userlist)
{
    $errors = array();
    //CHECK: check email validity
    for ($i = 0, $size = sizeof($userlist['email']); $i < $size; $i++) {
        if (!empty($userlist['email'][$i]) && !is_well_formed_email_address($userlist['email'][$i])) {
            $errors[$i] = TRUE;
        }
    }
    return $errors;
}
Пример #4
0
 /**
  * Check the value of the email field
  * (must be an email address, avoid duplication).
  *
  * @param $data email value
  * @return array containing errors
  **/
 public static function checkEmailField($data)
 {
     $errors = array();
     foreach ($data as $key => $value) {
         if (!empty($value)) {
             if (!is_well_formed_email_address($value)) {
                 $errors[] = get_lang('Invalid email address at line %key', array('%key' => $key));
             } elseif (array_search($value, $data) != $key) {
                 $errors[] = get_lang('Email address seems to be duplicate at line %key', array('%key' => $key));
             }
         }
     }
     return $errors;
 }
Пример #5
0
 /**
  * Validate value of a property
  *
  * @param string $name
  * @param string $value
  *
  */
 function validate_property($name, $value)
 {
     $valid = true;
     $property_def = $this->conf_def_property_list[$name];
     // init property type
     if (isset($property_def['type'])) {
         $type = $property_def['type'];
     } else {
         $type = null;
     }
     // init property label
     if (isset($property_def['label'])) {
         $label = $property_def['label'];
     } else {
         $label = $name;
     }
     // init property accepted value
     if (!empty($property_def['acceptedValue'])) {
         $acceptedValue = $property_def['acceptedValue'];
     } else {
         $acceptedValue = array();
     }
     if (isset($property_def['acceptedValueType'])) {
         switch ($property_def['acceptedValueType']) {
             case 'css':
                 $acceptedValue = array_merge($acceptedValue, $this->retrieve_accepted_values_from_folder(get_path('rootSys') . 'web/css/', 'folder', '.css'));
                 $acceptedValue = array_merge($acceptedValue, $this->retrieve_accepted_values_from_folder(get_path('rootSys') . 'platform/css', 'folder', '.css'));
                 break;
             case 'lang':
                 $acceptedValue = array_merge($acceptedValue, $this->retrieve_accepted_values_from_folder(get_path('rootSys') . 'claroline/lang', 'folder'));
                 break;
             case 'auth':
                 $acceptedValue = array_merge($acceptedValue, $this->retrieve_accepted_values_from_folder(get_path('rootSys') . 'claroline/auth/extauth/drivers', 'file', '.php'));
                 break;
             case 'editor':
                 $acceptedValue = array_merge($acceptedValue, $this->retrieve_accepted_values_from_folder(get_path('rootSys') . 'claroline/editor', 'folder'));
                 break;
             case 'timezone':
                 $acceptedValue = array_merge($acceptedValue, $this->get_timezone_list());
                 break;
         }
     }
     // validate property
     switch ($type) {
         case 'boolean':
             if (!is_bool($value) && !in_array(strtoupper($value), array('TRUE', 'FALSE', '1', '0'))) {
                 $this->backlog->failure(get_lang('%name should be boolean', array('%name' => $label)));
                 $valid = false;
             }
             break;
         case 'integer':
             if (!preg_match('/\\d+/i', $value)) {
                 $this->backlog->failure(get_lang('%name should be integer', array('%name' => $label)));
                 $valid = false;
             } elseif (isset($acceptedValue['max']) && $value > $acceptedValue['max']) {
                 $this->backlog->failure(get_lang('%name should be integer inferior or equal to %value', array('%name' => $label, '%value' => $acceptedValue['max'])));
                 $valid = false;
             } elseif (isset($acceptedValue['min']) && $value < $acceptedValue['min']) {
                 $this->backlog->failure(get_lang('%name should be integer superior or equal to %value', array('%name' => $label, '%value' => $acceptedValue['min'])));
                 $valid = false;
             }
             break;
         case 'enum':
             if (isset($acceptedValue) && is_array($acceptedValue)) {
                 if (!in_array($value, array_keys($acceptedValue))) {
                     $this->backlog->failure(get_lang('%value should be in enum list of %name', array('%value' => $value, '%name' => $label)));
                     $valid = false;
                 }
             }
             break;
         case 'multi':
             if (is_array($value)) {
                 foreach ($value as $item_value) {
                     if (!in_array($item_value, array_keys($acceptedValue))) {
                         $this->backlog->failure(get_lang('%value should be in the accepted value list of %name', array('%value' => $item_value, '%name' => $label)));
                         $valid = false;
                     }
                 }
             } else {
                 if (!empty($value)) {
                     $this->backlog->failure(get_lang('%name should be an array', array('%name' => $label)));
                     $valid = false;
                 }
             }
             break;
         case 'relpath':
             break;
         case 'syspath':
         case 'wwwpath':
             if (empty($value)) {
                 $this->backlog->failure(get_lang('Field \'%name\' is required', array('%name' => $label)));
                 $valid = false;
             }
             break;
         case 'regexp':
             if (isset($acceptedValue) && !preg_match('/' . $acceptedValue . '/i', $value)) {
                 $this->backlog->failure(get_lang('%name should be match %regular_expression', array('%name' => $label, '%regular_expression' => $acceptedValue)));
                 $valid = false;
             }
             break;
         case 'email':
             if (!empty($value)) {
                 if (!is_well_formed_email_address($value)) {
                     $this->backlog->failure(get_lang(' %email is not a valid e-mail address.', array('%email' => $value)));
                     $valid = false;
                 }
             }
             break;
         case 'string':
         case 'text':
         default:
             $valid = true;
     }
     return $valid;
 }
Пример #6
0
     // problem with url. try to repair
     // if  it  only the protocol missing add http
     if (preg_match('!^[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z0-9]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\\-\\._\\?\\,\'/\\\\+&%\\$#\\=~])*$!i', $institutionUrlForm) && preg_match($regexp, 'http://' . $institutionUrlForm)) {
         $institutionUrlForm = 'http://' . $institutionUrlForm;
     } else {
         $administrativeDataMissing = TRUE;
         $check_administrative_data[] = get_lang('Institution URL');
     }
 }
 if (empty($contactEmailForm) || empty($contactNameForm) || !is_well_formed_email_address($contactEmailForm)) {
     $administrativeDataMissing = TRUE;
     if (empty($contactNameForm)) {
         $check_administrative_data[] = get_lang('Contact name');
         $contactNameForm = $adminNameForm;
     }
     if (empty($contactEmailForm) || !is_well_formed_email_address($contactEmailForm)) {
         $check_administrative_data[] = get_lang('Contact email');
         if (empty($contactEmailForm)) {
             $contactEmailForm = $adminEmailForm;
         } else {
             $contactEmailForm = '';
         }
     }
 }
 if ($administrativeDataMissing) {
     $msg_missing_administrative_data = '<div class="claroDialogBox boxError">' . '<p>' . "\n" . '<strong>' . get_lang('Error') . '</strong> : ' . get_lang('Please enter missing information') . '</p>' . "\n" . '<ul>';
     foreach ($check_administrative_data as $missing_administrative_data) {
         $msg_missing_administrative_data .= '<li>' . $missing_administrative_data . '</li>';
     }
     $msg_missing_administrative_data .= '</ul>' . '</div>';
     $display = $cmd > DISP_ADMINISTRATIVE_SETTING ? DISP_ADMINISTRATIVE_SETTING : $cmd;