| Current Path : /home/h/a/p/happyrenas/old/huissier-express.fr/administration/2020/includes/ |
Linux webd005.cluster105.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 |
| Current File : /home/h/a/p/happyrenas/old/huissier-express.fr/administration/2020/includes/fonctions.php |
<?
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
function envoi_mail($from, $fromname, $reply, $destinataire, $destinataire_copie,$destinataire_copie_cachee, $pj, $embed_src,$embed_label, $matrice, $corps, $sujet) {
//https://github.com/PHPMailer/PHPMailer
global $dossier_de_base;
global $dossier_de_base_upload;
global $from;
global $fromname;
global $reply;
global $destinataire;
global $destinataire_copie;
global $destinataire_copie_cachee;
global $pj;
global $embed_src;
global $embed_label;
global $matrice;
global $corps;
global $sujet;
require_once $dossier_de_base.'phpmailer/src/PHPMailer.php';
require_once $dossier_de_base.'phpmailer/src/Exception.php';
$mail = new PHPMailer(true);
try {
$mail->setFrom($from, $fromname);
$mail->addAddress($destinataire);
$mail->addReplyTo($reply);
if ($destinataire_copie) {
foreach ($destinataire_copie as $value) {
$mail->addCC($value);
}
}
if ($destinataire_copie_cachee) {
foreach ($destinataire_copie_cachee as $value) {
$mail->addBCC($value);
}
}
if ($pj) {
foreach ($pj as $value) {
$mail->addAttachment($dossier_de_base_upload.$value);
}
}
include $dossier_de_base.$matrice;
if ($embed_src) {
foreach ($embed_src as $key=>$value) {
$mail->AddEmbeddedImage($dossier_de_base.$value, $embed_label[$key]);
}
}
$mail->isHTML(true);
$mail->Subject = $sujet;
$mail->Body = $message;
$mail->AltBody = $corps;
$mail->send();
return "email envoyé";
} catch (Exception $e) {
return "Une erreur a eu lieu : : {$mail->ErrorInfo}";
}
}
function nettoyerChaine($chaine)
{
$caracteres = array(
'é' => 'é',
'’' => '`',
'à' => 'à',
'è' => 'è',
'â' => 'â',
'ê' => 'ê',
''' => '',
'ï' => 'i',
'°' => ' degrés',
' ' => ' '
);
$chaine = strtr($chaine, $caracteres);
$chaine = str_replace("\n","-",$chaine);
$chaine = utf8_decode($chaine);
return $chaine;
}
function cleanNameFunction($name){
$name = preg_replace("/[^a-zA-Z0-9]+/", "", $name);
return $name;
}
function compress_upload($source, $destination, $quality) {
$info = getimagesize($source);
if ($info['mime'] == 'image/jpeg')
{$image = imagecreatefromjpeg($source);}
imagejpeg($image, $destination, $quality);
return $destination;
}
function get_browser_name($user_agent)
{
if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
elseif (strpos($user_agent, 'Edge')) return 'Edge';
elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
elseif (strpos($user_agent, 'Safari')) return 'Safari';
elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
return 'Non répertorié';
}
function recursive_glob($pattern)
{
$first_files = glob($pattern);
foreach (glob(dirname($pattern).'/*') as $dir)
{
$first_files = array_merge($first_files, recursive_glob($dir.'/'.basename($pattern)));
}
return $first_files;
}
function utf8_converter($array)
{
array_walk_recursive($array, function(&$item, $key){
if(!mb_detect_encoding($item, 'utf-8', true)){
$item = utf8_encode($item);
}
});
return $array;
}
///////////////////////////////////////////////////////////////
/////////////////////LES FONCTIONS/////////////////////////////
///////////////////////////////////////////////////////////////
function isferie($date)
{
if ($date === null)
{
$date = time();
}
$date = strtotime(date('m/d/Y',$date));
$year = date('Y',$date);
$easterDate = easter_date($year);
$easterDay = date('j', $easterDate);
$easterMonth = date('n', $easterDate);
$easterYear = date('Y', $easterDate);
$holidays = array(
// Dates fixes
mktime(0, 0, 0, 1, 1, $year), // 1er janvier
mktime(0, 0, 0, 5, 1, $year), // Fête du travail
mktime(0, 0, 0, 5, 8, $year), // Victoire des alliés
mktime(0, 0, 0, 7, 14, $year), // Fête nationale
mktime(0, 0, 0, 8, 15, $year), // Assomption
mktime(0, 0, 0, 11, 1, $year), // Toussaint
mktime(0, 0, 0, 11, 11, $year), // Armistice
mktime(0, 0, 0, 12, 25, $year), // Noel
// Dates variables
mktime(0, 0, 0, $easterMonth, $easterDay + 1, $easterYear),
mktime(0, 0, 0, $easterMonth, $easterDay + 39, $easterYear),
mktime(0, 0, 0, $easterMonth, $easterDay + 50, $easterYear),
);
return in_array($date, $holidays);
}
function returnDates($fromdate, $todate) {
$fromdate = \DateTime::createFromFormat('d/m/Y', $fromdate);
$todate = \DateTime::createFromFormat('d/m/Y', $todate);
return new \DatePeriod(
$fromdate,
new \DateInterval('P1D'),
$todate->modify('+1 day')
);
}
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
function cutString($string, $start, $length, $endStr = '…')
{
// si la taille de la chaine est inférieure ou égale à celle
// attendue on la retourne telle qu'elle
if( strlen( $string ) <= $length ) return $string;
// autrement on continue
// permet de couper la phrase aux caractères définis tout
// en prenant en compte la taille de votre $endStr et en
// re-précisant l'encodage du contenu récupéré
$str = mb_substr( $string, $start, $length - strlen( $endStr ) + 1, 'UTF-8');
// retourne la chaîne coupée avant la dernière espace rencontrée
// à laquelle s'ajoute notre $endStr
return substr( $str, 0, strrpos( $str,' ') ).''.$endStr;
}
function nomdemois($numero)
{
$mons = array("01" => "Janvier", "02" => "Fevrier", "03" => "Mars", "04" => "Avril", "05" => "Mai", "06" => "Juin", "07" => "Juillet", "08" => "Aout", "09" => "Septembre", "10" => "Octobre", "11" => "Novembre", "12" => "Décembre");
//$mons = array("01" => "Jan.", "02" => "Fév.", "03" => "Mars.", "04" => "Avr.", "05" => "Mai.", "06" => "Juin.", "07" => "Juil.", "08" => "Aout.", "09" => "Sept.", "10" => "Oct.", "11" => "Nov.", "12" => "Déc.");
return $mons[$numero];
}
function zipper($dir, $destination) {
// Get real path for our folder
$rootPath = realpath($dir);
if (!$destination) {$destination="file.zip";}
// Initialize archive object
$zip = new ZipArchive();
$zip->open($destination, ZipArchive::CREATE | ZipArchive::OVERWRITE);
// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
// Skip directories (they would be added automatically)
if (!$file->isDir())
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
// Add current file to archive
$zip->addFile($filePath, $relativePath);
}
}
// Zip archive will be created only after closing object
$zip->close();
}
function lister($dir)
{
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if ($file!='.' && $file!='..' && $file!='thumbnail')
{
$cpt=$cpt+1;
$matrice[$cpt] = array('nom' => $file);
}
}
closedir($dh);
return $matrice;
}
}
}
function scandir_by_mtime($folder) {
$dircontent = scandir($folder);
$arr = array();
foreach($dircontent as $filename) {
if ($filename != '.' && $filename != '..') {
if (filemtime($folder.$filename) === false) return false;
$dat = date("YmdHis", filemtime($folder.$filename));
$arr[$dat] = $filename;
}
}
if (!ksort($arr)) return false;
return $arr;
}
function imagethumb( $image_src , $image_dest = NULL , $max_size = 90, $expand = FALSE, $square = FALSE )
{
if( !file_exists($image_src) ) return FALSE;
// Récupère les infos de l'image
$fileinfo = getimagesize($image_src);
if( !$fileinfo ) return FALSE;
$width = $fileinfo[0];
$height = $fileinfo[1];
$type_mime = $fileinfo['mime'];
$type = str_replace('image/', '', $type_mime);
if( !$expand && max($width, $height)<=$max_size && (!$square || ($square && $width==$height) ) )
{
// L'image est plus petite que max_size
if($image_dest)
{
return copy($image_src, $image_dest);
}
else
{
header('Content-Type: '. $type_mime);
return (boolean) readfile($image_src);
}
}
// Calcule les nouvelles dimensions
$ratio = $width / $height;
if( $square )
{
$new_width = $new_height = $max_size;
if( $ratio > 1 )
{
// Paysage
$src_y = 0;
$src_x = round( ($width - $height) / 2 );
$src_w = $src_h = $height;
}
else
{
// Portrait
$src_x = 0;
$src_y = round( ($height - $width) / 2 );
$src_w = $src_h = $width;
}
}
else
{
$src_x = $src_y = 0;
$src_w = $width;
$src_h = $height;
if ( $ratio > 1 )
{
// Paysage
$new_width = $max_size;
$new_height = round( $max_size / $ratio );
}
else
{
// Portrait
$new_height = $max_size;
$new_width = round( $max_size * $ratio );
}
}
// Ouvre l'image originale
$func = 'imagecreatefrom' . $type;
if( !function_exists($func) ) return FALSE;
$image_src = $func($image_src);
$new_image = imagecreatetruecolor($new_width,$new_height);
// Gestion de la transparence pour les png
if( $type=='png' )
{
imagealphablending($new_image,false);
if( function_exists('imagesavealpha') )
imagesavealpha($new_image,true);
}
// Gestion de la transparence pour les gif
elseif( $type=='gif' && imagecolortransparent($image_src)>=0 )
{
$transparent_index = imagecolortransparent($image_src);
$transparent_color = imagecolorsforindex($image_src, $transparent_index);
$transparent_index = imagecolorallocate($new_image, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
imagefill($new_image, 0, 0, $transparent_index);
imagecolortransparent($new_image, $transparent_index);
}
// Redimensionnement de l'image
imagecopyresampled(
$new_image, $image_src,
0, 0, $src_x, $src_y,
$new_width, $new_height, $src_w, $src_h
);
// Enregistrement de l'image
$func = 'image'. $type;
if($image_dest)
{
$func($new_image, $image_dest);
}
else
{
header('Content-Type: '. $type_mime);
$func($new_image);
}
// Libération de la mémoire
imagedestroy($new_image);
return TRUE;
}
function checkid($id) {
if(!is_numeric($id)){
echo "<p>Invalid ID</p>";
exit;
}else{
return $id;
}
}
function stri_replace( $find, $replace, $string ) {
// Case-insensitive str_replace()
$parts = explode( strtolower($find), strtolower($string) );
$pos = 0;
foreach( $parts as $key=>$part ){
$parts[ $key ] = substr($string, $pos, strlen($part));
$pos += strlen($part) + strlen($find);
}
return( join( $replace, $parts ) );
}
function check_email_address($email) {
if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)) {
return false;
}
return true;
}
function show_user_level($type) {
switch ($type) {
case 0:
$show_user_level = "Administrator";
break;
case 1:
$show_user_level = "User";
break;
case 2:
$show_user_level = "Support Staff";
break;
case 3:
$show_user_level = "";
break;
}
return $show_user_level;
}
function show_type_name($type) {
switch ($type) {
case 0:
echo "Support Staff";
break;
case 1:
echo "Departments";
break;
case 2:
echo "Request Type";
break;
case 3:
echo "Device Type";
break;
}
}
function show_type_col($type) {
switch ($type) {
case 0:
$show_type_col = "call_staff";
break;
case 1:
$show_type_col = "call_department";
break;
case 2:
$show_type_col = "call_request";
break;
case 3:
$show_type_col = "call_device";
break;
}
return $show_type_col;
}
function call_status($value) {
switch ($value) {
case '0':
$value = "Active";
break;
case '1':
$value = "Closed";
break;
}
return $value;
}
///////////
function generatePassword($length=9, $strength=0) {
$vowels = 'aeuy';
$consonants = 'bdghjmnpqrstvz';
if ($strength & 1) {
$consonants .= 'BDGHJLMNPQRSTVWXZ';
}
if ($strength & 2) {
$vowels .= "AEUY";
}
if ($strength & 4) {
$consonants .= '23456789';
}
if ($strength & 8) {
$consonants .= '@#$%';
}
$password = '';
$alt = time() % 2;
for ($i = 0; $i < $length; $i++) {
if ($alt == 1) {
$password .= $consonants[(rand() % strlen($consonants))];
$alt = 0;
} else {
$password .= $vowels[(rand() % strlen($vowels))];
$alt = 1;
}
}
return $password;
}
function getIntersection($a1,$a2,$b1,$b2)
{
$a1 = strtotime($a1);
$a2 = strtotime($a2);
$b1 = strtotime($b1);
$b2 = strtotime($b2);
if($b1 >= $a2 || $a1 >= $b2 || $a2 <= $a1 || $b2 <= $b1)
{
return false;
}
$start = $a1 < $b1 ? $b1 : $a1;
$end = $a2 < $b2 ? $a2 : $b2;
return array('start' => $start, 'end' => $end);
}
?>