24 include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
25 require_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);
113 $s .=
'<input type="file" name="username" class="flat">';
127 global $conf, $langs, $_FILES;
129 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
132 ini_set(
'auto_detect_line_endings',
true);
136 $upload_dir = $conf->mailing->dir_temp;
140 $resupload =
dol_move_uploaded_file($_FILES[
'username'][
'tmp_name'], $upload_dir.
"/".$_FILES[
'username'][
'name'], 1, 0, $_FILES[
'username'][
'error']);
141 if (is_numeric($resupload) && $resupload > 0)
145 $file = $upload_dir.
"/".$_FILES[
'username'][
'name'];
146 $handle = @fopen($file,
"r");
153 while (!feof($handle))
156 $buffer = trim(fgets($handle));
157 $tab = explode(
';', $buffer, 4);
160 $firstname = $tab[2];
165 if (isValidEMail($email))
172 'firstname' => $firstname,
176 'source_type' =>
'file'
183 $langs->load(
"errors");
184 $msg = $langs->trans(
"ErrorFoundBadEmailInFile", $i, $cpt, $email);
185 if (!empty($msg)) $this->error = $msg;
186 else $this->error =
'ErrorFoundBadEmailInFile '.$i.
' '.$cpt.
' '.$email;
197 $this->error = $langs->trans(
"ErrorFaildToOpenFile");
201 dol_syslog(get_class($this).
"::add_to_target mailing ".$cpt.
" targets found");
203 $langs->load(
"errors");
206 $this->error =
'<div class="error">'.$langs->trans(
"ErrorFileNotUploaded").
'</div>';
207 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload))
209 $this->error =
'<div class="error">'.$langs->trans(
"ErrorFileIsInfectedWithAVirus").
'</div>';
212 $this->error =
'<div class="error">'.$langs->trans($resupload).
'</div>';
217 ini_set(
'auto_detect_line_endings',
false);
219 return parent::addTargetsToDatabase($mailing_id, $cibles);
$conf db
API class for accounts.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles= 'addedfile', $upload_dir= '')
Make control on an uploaded file from an GUI page and move it to final destination.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
Parent class of emailing target selectors modules.