| Current Path : /home/happyrenas/old/devis-huissier.fr/old/administration/panel/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/happyrenas/old/devis-huissier.fr/old/administration/panel/includes/fonctions.php |
<?
///////////////////////////////////////////////////////////////
/////////////////////LES FONCTIONS/////////////////////////////
///////////////////////////////////////////////////////////////
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 = '[&hellip]')
{
// 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");
return $mons[$numero];
}
/* creates a compressed zip file */
function create_zip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
if(file_exists($file)) {
$valid_files[] = $file;
}
}
}
//if we have good files...
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
//add the files
foreach($valid_files as $file) {
$zip->addFile($file,$file);
}
//debug
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
//close the zip -- done!
$zip->close();
//check to make sure the file exists
return file_exists($destination);
}
else
{
return false;
}
}
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 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);
}
?>