26include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
35 public $name =
'EmailsFromFile';
37 public $desc =
'EMails from a file';
42 public $require_module = array();
47 public $require_admin = 0;
52 public $picto =
'generic';
53 public $tooltip =
'UseFormatFileEmailToTarget';
78 $langs->load(
"users");
108 return $langs->trans(
'LineInFile',
$id);
124 $maxmin = $maxfilesizearray[
'maxmin'];
126 $s .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
128 $s .=
'<input type="file" name="username" class="flat">';
142 global $conf, $langs, $_FILES;
144 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
147 ini_set(
'auto_detect_line_endings',
true);
151 $upload_dir = $conf->mailing->dir_temp;
154 $resupload =
dol_move_uploaded_file($_FILES[
'username'][
'tmp_name'], $upload_dir.
"/".$_FILES[
'username'][
'name'], 1, 0, $_FILES[
'username'][
'error']);
155 if (is_numeric($resupload) && $resupload > 0) {
158 $file = $upload_dir.
"/".$_FILES[
'username'][
'name'];
159 $handle = @fopen($file,
"r");
165 while (!feof($handle)) {
167 $buffer = trim(fgets($handle));
168 $tab = explode(
';', $buffer, 4);
175 if (!empty($buffer)) {
178 if ($old != $email) {
182 'firstname' => $firstname,
186 'source_type' =>
'file'
193 $langs->load(
"errors");
194 $msg = $langs->trans(
"ErrorFoundBadEmailInFile", $i, $cpt, $email);
198 $this->error =
'ErrorFoundBadEmailInFile '.$i.
' '.$cpt.
' '.$email;
209 $this->error = $langs->trans(
"ErrorFaildToOpenFile");
213 dol_syslog(get_class($this).
"::add_to_target mailing ".$cpt.
" targets found");
215 $langs->load(
"errors");
216 if ($resupload < 0) {
217 $this->error =
'<div class="error">'.$langs->trans(
"ErrorFileNotUploaded").
'</div>';
218 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
219 $this->error =
'<div class="error">'.$langs->trans(
"ErrorFileIsInfectedWithAVirus").
'</div>';
221 $this->error =
'<div class="error">'.$langs->trans($resupload).
'</div>';
226 ini_set(
'auto_detect_line_endings',
false);
228 return parent::addTargetsToDatabase($mailing_id, $cibles);
$id
Support class for third parties, contacts, members, users or resources.
Parent class of emailing target selectors modules.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $keyforsourcefile='addedfile', $upload_dir='', $mode=0)
Check validity of a file upload from an GUI page, and move it to its final destination.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
getMaxFileSizeArray()
Return the max allowed for file upload.