24include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
25require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
33 public $name =
'EmailsFromFile';
35 public $desc =
'EMails from a file';
36 public $require_module = array();
37 public $require_admin = 0;
42 public $picto =
'generic';
43 public $tooltip =
'UseFormatFileEmailToTarget';
68 $langs->load(
"users");
95 public function url($id)
98 return $langs->trans(
'LineInFile', $id);
114 $maxmin = $maxfilesizearray[
'maxmin'];
116 $s .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
118 $s .=
'<input type="file" name="username" class="flat">';
132 global $conf, $langs, $_FILES;
134 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
137 ini_set(
'auto_detect_line_endings',
true);
141 $upload_dir = $conf->mailing->dir_temp;
144 $resupload =
dol_move_uploaded_file($_FILES[
'username'][
'tmp_name'], $upload_dir.
"/".$_FILES[
'username'][
'name'], 1, 0, $_FILES[
'username'][
'error']);
145 if (is_numeric($resupload) && $resupload > 0) {
148 $file = $upload_dir.
"/".$_FILES[
'username'][
'name'];
149 $handle = @fopen($file,
"r");
155 while (!feof($handle)) {
157 $buffer = trim(fgets($handle));
158 $tab = explode(
';', $buffer, 4);
165 if (!empty($buffer)) {
168 if ($old != $email) {
172 'firstname' => $firstname,
176 'source_type' =>
'file'
183 $langs->load(
"errors");
184 $msg = $langs->trans(
"ErrorFoundBadEmailInFile", $i, $cpt, $email);
188 $this->error =
'ErrorFoundBadEmailInFile '.$i.
' '.$cpt.
' '.$email;
199 $this->error = $langs->trans(
"ErrorFaildToOpenFile");
203 dol_syslog(get_class($this).
"::add_to_target mailing ".$cpt.
" targets found");
205 $langs->load(
"errors");
206 if ($resupload < 0) {
207 $this->error =
'<div class="error">'.$langs->trans(
"ErrorFileNotUploaded").
'</div>';
208 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
209 $this->error =
'<div class="error">'.$langs->trans(
"ErrorFileIsInfectedWithAVirus").
'</div>';
211 $this->error =
'<div class="error">'.$langs->trans($resupload).
'</div>';
216 ini_set(
'auto_detect_line_endings',
false);
218 return parent::addTargetsToDatabase($mailing_id, $cibles);
Parent class of emailing target selectors modules.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
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.