Remove microtime_float
This commit is contained in:
parent
126c6c0b2e
commit
d743b072cc
@ -113,7 +113,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
|
||||
if (!empty($nic)) {
|
||||
$nic = str_pad($nic, 5, '0', STR_PAD_LEFT);
|
||||
}
|
||||
if (!valideData($siren, 9, 9,'N')) //Siren non précisé ou incorrect.
|
||||
if (!Metier_Util_String::valideData($siren, 9, 9,'N')) //Siren non précisé ou incorrect.
|
||||
return $erreur;
|
||||
elseif ($siren*1==0) // Siren vide
|
||||
return $erreur;
|
||||
@ -140,7 +140,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
|
||||
return $erreur;
|
||||
}
|
||||
} else {
|
||||
if (!valideData($nic,1,5,'N')) // Nic de format incorrect.
|
||||
if (!Metier_Util_String::valideData($nic,1,5,'N')) // Nic de format incorrect.
|
||||
return $erreur;
|
||||
|
||||
$SIRET=$siren.$nic;
|
||||
@ -184,7 +184,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
|
||||
{
|
||||
if (!$this->valideSiren($siren))
|
||||
return -1;
|
||||
elseif (!valideData($numEtab,1,4,'N')) // Nic de format incorrect.
|
||||
elseif (!Metier_Util_String::valideData($numEtab,1,4,'N')) // Nic de format incorrect.
|
||||
return -1;
|
||||
else {
|
||||
for ($cle=0; $cle<10; $cle++) {
|
||||
|
@ -66,14 +66,14 @@ class Metier_Partenaires_MTva
|
||||
'ISO'=>'FR',
|
||||
'MS'=>'FR'
|
||||
);*/
|
||||
$tdeb = microtime_float();
|
||||
$tdeb = microtime(true);
|
||||
// $url='http://ec.europa.eu/taxation_customs/vies/cgi-bin/viesquer';
|
||||
// $referer='http://ec.europa.eu/taxation_customs/vies/fr/vieshome.htm';
|
||||
$url='http://ec.europa.eu/taxation_customs/vies/viesquer.do';
|
||||
$referer='http://ec.europa.eu/taxation_customs/vies/';
|
||||
|
||||
$page=getUrl($url, '', $postData, $referer, false, 'ec.europa.eu', '', 15);
|
||||
$duree = round(microtime_float()-$tdeb, 3);
|
||||
$duree = round(microtime(true)-$tdeb, 3);
|
||||
if ($page['err_num']<>0) {
|
||||
Metier_Util_Log::write('W', 'TVA Erreur CURL n°'. $page['err_num'] .', '. $page['err_msg'] ." sur le Siren $siren, numéro de TVA = FR $cle $siren. Durée = $duree s !", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
||||
$this->vatNumber="FR$cle$siren";
|
||||
@ -213,7 +213,7 @@ class Metier_Partenaires_MTva
|
||||
}
|
||||
}
|
||||
|
||||
if (!valideData($siren, 9, 9,'N')) //Siren non précisé ou incorrect.
|
||||
if (!Metier_Util_String::valideData($siren, 9, 9,'N')) //Siren non précisé ou incorrect.
|
||||
return $erreur;
|
||||
elseif ($siren*1==0) // Siren vide
|
||||
return $erreur;
|
||||
@ -240,7 +240,7 @@ class Metier_Partenaires_MTva
|
||||
return $erreur;
|
||||
}
|
||||
} else {
|
||||
if (!valideData($nic,1,5,'N')) // Nic de format incorrect.
|
||||
if (!Metier_Util_String::valideData($nic,1,5,'N')) // Nic de format incorrect.
|
||||
return $erreur;
|
||||
|
||||
$SIRET=$siren.$nic;
|
||||
|
@ -47,7 +47,7 @@ class Metier_Util_Db
|
||||
} else {
|
||||
$query = 'INSERT INTO '.$table.' ('.$fields.') VALUES ('.$values.');';
|
||||
}
|
||||
if ($debug) $tdeb = microtime_float();
|
||||
if ($debug) $tdeb = microtime(true);
|
||||
|
||||
try {
|
||||
$stmt = $this->db->query($query);
|
||||
@ -99,7 +99,7 @@ class Metier_Util_Db
|
||||
$query.=' WHERE '.$where;
|
||||
if ($limit>0) $query.=" LIMIT $limit";
|
||||
|
||||
if ($debug) $tdeb=microtime_float();
|
||||
if ($debug) $tdeb = microtime(true);
|
||||
|
||||
try {
|
||||
$stmt = $this->db->query($query);
|
||||
@ -139,7 +139,7 @@ class Metier_Util_Db
|
||||
$query='DELETE FROM '.$table.' WHERE '.$where.';';
|
||||
}
|
||||
|
||||
if ($debug) $tdeb=microtime_float();
|
||||
if ($debug) $tdeb = microtime(true);
|
||||
|
||||
try {
|
||||
$stmt = $this->db->query($query);
|
||||
@ -176,7 +176,7 @@ class Metier_Util_Db
|
||||
|
||||
$query="SELECT $fields FROM $table WHERE $where;";
|
||||
|
||||
if ($debug) $tdeb=microtime_float();
|
||||
if ($debug) $tdeb = microtime(true);
|
||||
|
||||
try {
|
||||
$stmt = $this->db->query($query);
|
||||
@ -240,7 +240,7 @@ class Metier_Util_Db
|
||||
public function trace($query, $res='', $tdeb = null)
|
||||
{
|
||||
if ( $tdeb === null) {
|
||||
$duree = substr(''.microtime_float()-$tdeb, 0, 5);
|
||||
$duree = microtime(true)-$tdeb;
|
||||
} else {
|
||||
$duree = 'N/D';
|
||||
}
|
||||
|
@ -178,10 +178,9 @@ class SdMetier_Scoring_Base extends SdMetier_Scoring_Vars
|
||||
FROM jo.scores_surveillance
|
||||
WHERE siren=$siren
|
||||
ORDER BY indiScoreDate DESC";
|
||||
$iDb = new WDB();
|
||||
$ret = $iDb->query($query);
|
||||
$ret = $this->db->query($query);
|
||||
$tabRet = array();
|
||||
while( $ret = $iDb->fetch(MYSQL_ASSOC) ) {
|
||||
while( $ret = $this->db->fetch(MYSQL_ASSOC) ) {
|
||||
$tabRet[] = array (
|
||||
'siren' => $ret['siren'],
|
||||
'actif' => $ret['actif'],
|
||||
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
class WChiffes
|
||||
{
|
||||
private static $tabChiffresEnLEttres = array(
|
||||
0=>'zéro',
|
||||
1=>'un',
|
||||
2=>'deux',
|
||||
3=>'trois',
|
||||
4=>'quatre',
|
||||
5=>'cinq',
|
||||
6=>'six',
|
||||
7=>'sept',
|
||||
8=>'huit',
|
||||
9=>'neuf',
|
||||
10=>'dix',
|
||||
11=>'onze',
|
||||
12=>'douze',
|
||||
13=>'treize',
|
||||
14=>'quatorze',
|
||||
15=>'quinze',
|
||||
16=>'seize',
|
||||
17=>'dix sept',
|
||||
18=>'dix huit',
|
||||
19=>'dix neuf',
|
||||
20=>'vingt',
|
||||
21=>'vingt et un',
|
||||
22=>'vingt deux',
|
||||
23=>'vingt trois',
|
||||
24=>'vingt quatre',
|
||||
25=>'vingt cinq',
|
||||
26=>'vingt six',
|
||||
27=>'vingt sept',
|
||||
28=>'vingt huit',
|
||||
29=>'vingt neuf',
|
||||
30=>'trente',
|
||||
40=>'quarante',
|
||||
50=>'cinquante',
|
||||
60=>'soixante',
|
||||
70=>'soixante dix',
|
||||
80=>'quatre vingt',
|
||||
90=>'quatre vingt dix'
|
||||
);
|
||||
|
||||
public function ChiffresEnLettres($chiffre)
|
||||
{
|
||||
return array_search($chiffre, self::$tabChiffresEnLEttres);
|
||||
}
|
||||
}
|
@ -1,199 +0,0 @@
|
||||
<?php
|
||||
require_once 'framework/common/chiffres.php';
|
||||
define ('TODAY', date('Ymd'));
|
||||
|
||||
/**
|
||||
* Classe de gestion des méthodes relatives à la date et à l'heure
|
||||
*/
|
||||
class WDate
|
||||
{
|
||||
private static $tabMoisEnLettres = array(
|
||||
1 => 'Janvier',
|
||||
2 => 'Février',
|
||||
3 => 'Mars',
|
||||
4 => 'Avril',
|
||||
5 => 'Mai',
|
||||
6 => 'Juin',
|
||||
7 => 'Juillet',
|
||||
8 => 'Août',
|
||||
9 => 'Septembre',
|
||||
10 => 'Octobre',
|
||||
11 => 'Novembre',
|
||||
12 => 'Décembre'
|
||||
);
|
||||
|
||||
/** Retourne le numéro du mois donné au format texte (janvier, mars, etc...)
|
||||
* @param string Mois en toute lettres (janvier, mars, etc...)
|
||||
* @return string Mois en Chiffe (1, 3, 12) / false en cas d'erreur
|
||||
*/
|
||||
public function getNumMois($moisEnLettres)
|
||||
{
|
||||
foreach (self::$tabMoisEnLettres as $num=>$mois)
|
||||
$tabMoisSansAccents[$num]=strtr($mois, 'ééûÉÉÛ','eeueeu');
|
||||
return array_search(ucfirst(strtolower(strtr($moisEnLettres, 'ééûÉÉÛ','eeuEEU'))), $tabMoisSansAccents);
|
||||
}
|
||||
|
||||
/** Retourne le libellé nu numéro du mois passé en paramètre
|
||||
* @param int $moisEnChiffre
|
||||
* @return string Libellé du mois / false si le mois passé en paramètre est invalide
|
||||
*/
|
||||
public function getLibelleMois($moisEnChiffre)
|
||||
{
|
||||
if ($moisEnChiffre>0 && $moisEnChiffre<13)
|
||||
return self::$tabMoisEnLettres[$moisEnChiffre];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Retourne le nombre de mois entre 2 dates au format Ymd
|
||||
**
|
||||
** @param int $dateDeb Date de début au format Ymd
|
||||
** @param int $dateFin Date de fin (ultérieur à la date de début) au format Ymd
|
||||
** @return int Nombre de mois
|
||||
**/
|
||||
function nbMoisEntre($dateDeb, $dateFin=TODAY)
|
||||
{
|
||||
$dDeb=explode('-', Wdate::dateT('Ymd','Y-m-d', $dateDeb));
|
||||
$dFin=explode('-', Wdate::dateT('Ymd','Y-m-d', $dateFin));
|
||||
return ($dFin[0]*12+$dFin[1])-($dDeb[0]*12+$dDeb[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Conversion de formats de dates selon les formats de dates définits en php
|
||||
* @param string Format de la date d'entrée
|
||||
* @param string Format de la date de sortie
|
||||
* @param string Date d'entrée
|
||||
* @return string Date formatée
|
||||
*/
|
||||
public function dateT($formatIN, $formatOUT, $date)
|
||||
{
|
||||
$M='';
|
||||
switch ($formatIN) {
|
||||
case 'd M Y': $tmp=explode(' ', $date); $d=str_replace('1er', '1', $tmp[0]); $m=self::getNumMois($tmp[1]); $Y=$tmp[2]; break;
|
||||
case 'dMY': $Y=substr($date,-4);
|
||||
if (substr($date,0,3)=='1er') { $d=1; $posM=3; }
|
||||
elseif (is_numeric(substr($date,1,1))) { $d=substr($date,0,2); $posM=2; }
|
||||
else { $d=substr($date,0,1); $posM=1; }
|
||||
$M=trim(substr($date, $posM, strlen($date)-4-$posM));
|
||||
$m=self::getNumMois($M);
|
||||
break;
|
||||
case 'Ymd': $d=substr($date,6,2); $m=substr($date,4,2); $Y=substr($date,0,4); break;
|
||||
case 'ymd': $d=substr($date,4,2); $m=substr($date,2,2); $Y=substr($date,0,2);
|
||||
if ($Y<50) $Y='20'.$Y; else $Y='19'.$Y; break;
|
||||
case 'Y-m-d': $d=substr($date,8,2); $m=substr($date,5,2); $Y=substr($date,0,4); break;
|
||||
case 'Y-m': $d=1; $m=substr($date,5,2); $Y=substr($date,0,4); break;
|
||||
case 'd/m/Y': $tmp=explode('/', $date); $d=$tmp[0]; $m=$tmp[1]; $Y=$tmp[2]; break;
|
||||
case 'd.m.Y': $tmp=explode('.', $date); $d=$tmp[0]; $m=$tmp[1]; $Y=$tmp[2]; break;
|
||||
case 'd/m/y': $tmp=explode('/', $date); $d=$tmp[0]; $m=$tmp[1];
|
||||
if ($tmp[2]<date('y')) $Y='20'.$tmp[2]; else $Y='19'.$tmp[2]; break;
|
||||
case 'd-m-Y': $tmp=explode('-', $date); $d=$tmp[0]; $m=$tmp[1]; $Y=$tmp[2]; break;
|
||||
case 'm/d/Y': $tmp=explode('/', $date); $d=$tmp[1]; $m=$tmp[0]; $Y=$tmp[2]; break;
|
||||
case 'dmY': $d=substr($date,0,2); $m=substr($date,2,2); $Y=substr($date,4,4); break;
|
||||
case 'dmy': $d=substr($date,0,2); $m=substr($date,2,2); $Y=substr($date,4,2);
|
||||
if ($Y<50) $Y='20'.$Y; else $Y='19'.$Y; break;
|
||||
default: return $date;
|
||||
}
|
||||
|
||||
if ($m*1>0 && $m*1<10) $m='0'.($m*1); if ($d*1>0 && $d*1<10) $d='0'.($d*1);
|
||||
|
||||
switch ($formatOUT) {
|
||||
case 'd/m/Y': return $d.'/'.$m.'/'.$Y; break;
|
||||
case 'm/Y': return $m.'/'.$Y; break;
|
||||
case 'd M Y': return $d.' '.self::$tabMoisEnLettres[$m*1].' '.$Y; break;
|
||||
case 'M Y': return self::$tabMoisEnLettres[$m*1].' '.$Y; break;
|
||||
case 'Y': return $Y; break;
|
||||
case 'm': return $m; break;
|
||||
case 'd': return $d; break;
|
||||
case 'Ym': return $Y.$m; break;
|
||||
case 'Ymd': return $Y.$m.$d; break;
|
||||
case 'Y-m-d': return $Y.'-'.$m.'-'.$d; break;
|
||||
case 'Y/m/d': return $Y.'/'.$m.'/'.$d; break;
|
||||
default: return $date;
|
||||
}
|
||||
}
|
||||
|
||||
/** Calcul de la date après application de la période textuelle (deux ans, six mois, quinze jours, etc...)
|
||||
* @todo Fonction ne fonctionnant qu'avec un chiffre en un seul mot du genre dix mais pas quatre vingt dix !!!
|
||||
* @param date $dateIN au format Ymd
|
||||
* @param string $period (ex : cinq mois, six ans, un jour, 3 mois)
|
||||
* @return date
|
||||
*/
|
||||
function period2Days($dateIN, $period, $inThePast=false)
|
||||
{
|
||||
$dateV=self::dateT('Ymd', 'Ymd', $dateIN);
|
||||
if ($dateV<>$dateIN) return NULL;
|
||||
$d=substr($dateIN,6,2);
|
||||
$m=substr($dateIN,4,2);
|
||||
$Y=substr($dateIN,0,4);
|
||||
$period=strtolower(trim(strtr($period, "-.,", ' ')));
|
||||
if ($period=='') return NULL;
|
||||
$tabP=explode(' ', $period);
|
||||
if ($tabP[0]*1>0) $chiffre=$tabP[0]*1*1;
|
||||
else $chiffre=WChiffes::ChiffresEnLettres($tabP[0]);
|
||||
if ($inThePast) $chiffre=-1*$chiffre;
|
||||
switch (end($tabP)) {
|
||||
case 'mois': $dateOUT=date('Ymd', mktime(0, 0, 0, $m+$chiffre, $d, $Y)); break;
|
||||
case 'an':
|
||||
case 'ans': $dateOUT=date('Ymd', mktime(0, 0, 0, $m, $d, $Y+$chiffre)); break;
|
||||
case 'jour':
|
||||
case 'jours': $dateOUT=date('Ymd', mktime(0, 0, 0, $m, $d+$chiffre, $Y)); break;
|
||||
default: $dateOUT=NULL;
|
||||
}
|
||||
return $dateOUT;
|
||||
}
|
||||
|
||||
|
||||
/** le jour est il ferié
|
||||
* @param date $date Date au format SSAA-MM-JJ ou SSAAMMJJ
|
||||
* @param bool $weekend Considérer les WeekEnd comme feriés ? 1=Oui
|
||||
* @return bool
|
||||
**/
|
||||
function jourFerie($date, $weekend=false)
|
||||
{
|
||||
$date =str_replace('-','',strtr($date, '/.:','---'));
|
||||
$jour =self::dateT('Ymd', 'd', $date);
|
||||
$mois =self::dateT('Ymd', 'm', $date);
|
||||
$annee=self::dateT('Ymd', 'Y', $date);
|
||||
$ferie=false;
|
||||
|
||||
// Jours feriées fixes
|
||||
if($jour == 1 && $mois == 1) $ferie = true; // 1er janvier
|
||||
if($jour == 1 && $mois == 5) $ferie = true; // 1er mai
|
||||
if($jour == 8 && $mois == 5) $ferie = true; // 8 mai
|
||||
if($jour == 14 && $mois == 7) $ferie = true; // 14 juillet
|
||||
if($jour == 15 && $mois == 8) $ferie = true; // 15 aout
|
||||
if($jour == 1 && $mois == 11) $ferie = true; // 1 novembre
|
||||
if($jour == 11 && $mois == 11) $ferie = true; // 11 novembre
|
||||
if($jour == 25 && $mois == 12) $ferie = true; // 25 décembre
|
||||
|
||||
// fêtes religieuses mobiles
|
||||
$pak = @easter_date($annee);
|
||||
$jp = date("d", $pak);
|
||||
$mp = date("m", $pak);
|
||||
if($jp == $jour && $mp == $mois){ $ferie = true;} // Pâques
|
||||
$lpk = mktime(date("H", $pak), date("i", $pak), date("s", $pak), date("m", $pak), date("d", $pak) +1, date("Y", $pak) );
|
||||
$jp = date("d", $lpk);
|
||||
$mp = date("m", $lpk);
|
||||
if($jp == $jour && $mp == $mois){ $ferie = true; }// Lundi de Pâques
|
||||
$asc = mktime(date("H", $pak), date("i", $pak), date("s", $pak), date("m", $pak), date("d", $pak) + 39, date("Y", $pak) );
|
||||
$jp = date("d", $asc);
|
||||
$mp = date("m", $asc);
|
||||
if($jp == $jour && $mp == $mois){ $ferie = true;}//ascension
|
||||
$pe = mktime(date("H", $pak), date("i", $pak), date("s", $pak), date("m", $pak), date("d", $pak) + 49, date("Y", $pak) );
|
||||
$jp = date("d", $pe);
|
||||
$mp = date("m", $pe);
|
||||
if($jp == $jour && $mp == $mois) {$ferie = true;}// Pentecôte
|
||||
$lp = mktime(date("H", $asc), date("i", $pak), date("s", $pak), date("m", $pak), date("d", $pak) + 50, date("Y", $pak) );
|
||||
$jp = date("d", $lp);
|
||||
$mp = date("m", $lp);
|
||||
if($jp == $jour && $mp == $mois) {$ferie = true;}// lundi Pentecôte
|
||||
|
||||
// Samedis et Dimanches
|
||||
if ($weekend) {
|
||||
$jour_sem = date('N',mktime(0,0,0, $mois, $jour, $annee));
|
||||
if($jour_sem>5) $ferie = true;
|
||||
}
|
||||
|
||||
return $ferie;
|
||||
}
|
||||
}
|
@ -1,339 +0,0 @@
|
||||
<?php
|
||||
class WDB
|
||||
{
|
||||
/**
|
||||
* @var Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
protected $db = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var unknown
|
||||
*/
|
||||
protected $result = null;
|
||||
|
||||
protected $errorCode = 0;
|
||||
|
||||
protected $errorMsg = '';
|
||||
|
||||
public function __construct( $db = null )
|
||||
{
|
||||
if ($db === null) {
|
||||
$this->db = Zend_Db_Table::getDefaultAdapter();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* INSERTION d'un tableau dans une table.
|
||||
* Les index doivent avoir les mêmes noms que les champs.
|
||||
* @param string Table
|
||||
* @param array Valeurs insérer
|
||||
* @return int Dernière valeur de l'auto-incrément, 1 si pas d'auto-incrément et 0 si erreur
|
||||
*/
|
||||
public function insert($table, $toAdd, $debug=false, $low_priority=false)
|
||||
{
|
||||
$this->errorCode = 0;
|
||||
$this->errorMsg = '';
|
||||
|
||||
$fields = implode(array_keys($toAdd), ',');
|
||||
foreach (array_values($toAdd) as $key=>$array_values)
|
||||
$tmp[$key]=checkaddslashes($array_values);
|
||||
|
||||
$values = "'".implode(array_values($tmp), "','")."'"; # better
|
||||
$values = str_replace("'NULL'", 'NULL', $values);
|
||||
|
||||
if ($low_priority) {
|
||||
$query = 'INSERT INTO '.$table.' ('.$fields.') VALUES ('.$values.');';
|
||||
} else {
|
||||
$query = 'INSERT INTO '.$table.' ('.$fields.') VALUES ('.$values.');';
|
||||
}
|
||||
if ($debug) $tdeb = microtime_float();
|
||||
|
||||
try {
|
||||
$stmt = $this->db->query($query);
|
||||
$res = $this->db->lastInsertId();
|
||||
if ($debug) $this->trace($query, $res, $tdeb);
|
||||
if ( $res == 0 ) {
|
||||
return true;
|
||||
}
|
||||
return $res;
|
||||
} catch(Zend_Db_Exception $e) {
|
||||
$this->errorCode = $e->getCode();
|
||||
$this->errorMsg = $e->getMessage();
|
||||
$this->trace($query);
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Database Update
|
||||
* @param unknown $table
|
||||
* @param unknown $update
|
||||
* @param unknown $where
|
||||
* @param string $debug
|
||||
* @param number $limit
|
||||
* @param string $low_priority
|
||||
* @return resource
|
||||
*/
|
||||
public function update($table, $update, $where, $debug=false, $limit=0, $low_priority=false)
|
||||
{
|
||||
$this->errorCode = 0;
|
||||
$this->errorMsg = '';
|
||||
|
||||
if ($low_priority) {
|
||||
$query='UPDATE '.$table.' SET ';
|
||||
} else {
|
||||
$query='UPDATE '.$table.' SET ';
|
||||
}
|
||||
$i=0;
|
||||
foreach ($update as $field => $value) {
|
||||
$query.= ' '.$field."=".$this->db->quote($value);
|
||||
$i++;
|
||||
if ($i<count($update)) {
|
||||
$query.= ',';
|
||||
}
|
||||
}
|
||||
$query = str_replace("'NULL'", 'NULL', $query);
|
||||
$query.=' WHERE '.$where;
|
||||
if ($limit>0) $query.=" LIMIT $limit";
|
||||
|
||||
if ($debug) $tdeb=microtime_float();
|
||||
|
||||
try {
|
||||
$stmt = $this->db->query($query);
|
||||
$res = $stmt->rowCount();
|
||||
if ($debug) $this->trace($query, $res, $tdeb);
|
||||
if ( $res == 0 ) {
|
||||
return false;
|
||||
}
|
||||
return $res;
|
||||
} catch(Zend_Db_Exception $e) {
|
||||
$this->errorCode = $e->getCode();
|
||||
$this->errorMsg = $e->getMessage();
|
||||
$this->trace($query, $res, $tdeb);
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Database delete
|
||||
* @param string $table
|
||||
* @param string $where
|
||||
* @param string $debug
|
||||
* @param string $low_priority
|
||||
* @return resource
|
||||
*/
|
||||
public function delete($table, $where, $debug=false, $low_priority=false)
|
||||
{
|
||||
$this->errorCode = 0;
|
||||
$this->errorMsg = '';
|
||||
|
||||
if ($low_priority)
|
||||
$query='DELETE QUICK FROM '.$table.' WHERE '.$where.';';
|
||||
else
|
||||
$query='DELETE FROM '.$table.' WHERE '.$where.';';
|
||||
|
||||
if ($debug) $tdeb=microtime_float();
|
||||
|
||||
try {
|
||||
$stmt = $this->db->query($query);
|
||||
$res = $this->db->lastInsertId();
|
||||
if ($debug) $this->trace($query, $res, $tdeb);
|
||||
if ( $res == 0 ) {
|
||||
$res = true;
|
||||
}
|
||||
return $res;
|
||||
} catch(Zend_Db_Exception $e) {
|
||||
$this->errorCode = $e->getCode();
|
||||
$this->errorMsg = $e->getMessage();
|
||||
$this->trace($query, $res, $tdeb);
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Database select
|
||||
* @param string $table
|
||||
* @param string $fields
|
||||
* @param string $where
|
||||
* @param string $debug
|
||||
* @param string $assoc
|
||||
* @param string $huge
|
||||
* @return boolean|multitype:multitype: |number
|
||||
*/
|
||||
public function select($table, $fields, $where, $debug=false, $assoc=MYSQL_BOTH, $huge=false)
|
||||
{
|
||||
$this->errorCode = 0;
|
||||
$this->errorMsg = '';
|
||||
|
||||
$query="SELECT $fields FROM $table WHERE $where;";
|
||||
|
||||
if ($debug) $tdeb=microtime_float();
|
||||
|
||||
try {
|
||||
$stmt = $this->db->query($query);
|
||||
$this->result = $stmt;
|
||||
} catch(Zend_Db_Exception $e) {
|
||||
$this->errorCode = $e->getCode();
|
||||
$this->errorMsg = $e->getMessage();
|
||||
$this->trace($query);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !$huge ) {
|
||||
switch($assoc) {
|
||||
case MYSQL_NUM:
|
||||
$mode = Zend_Db::FETCH_NUM;
|
||||
break;
|
||||
case MYSQL_ASSOC:
|
||||
$mode = Zend_Db::FETCH_ASSOC;
|
||||
break;
|
||||
case MYSQL_BOTH:
|
||||
$mode = Zend_Db::FETCH_BOTH;
|
||||
break;
|
||||
}
|
||||
$tab = $stmt->fetchAll($mode);
|
||||
if ($debug) $this->trace($query, sizeof($tab), $tdeb);
|
||||
return $tab;
|
||||
} else {
|
||||
$nbRows = $stmt->rowCount();
|
||||
if ($debug) $this->trace($query, $nbRows, $tdeb);
|
||||
return $nbRows;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $assoc
|
||||
* @return multitype:
|
||||
*/
|
||||
public function fetch($assoc=MYSQL_BOTH)
|
||||
{
|
||||
switch($assoc) {
|
||||
case MYSQL_NUM:
|
||||
$mode = Zend_Db::FETCH_NUM;
|
||||
break;
|
||||
case MYSQL_ASSOC:
|
||||
$mode = Zend_Db::FETCH_ASSOC;
|
||||
break;
|
||||
case MYSQL_BOTH:
|
||||
$mode = Zend_Db::FETCH_BOTH;
|
||||
break;
|
||||
}
|
||||
return $this->result->fetch($mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trace
|
||||
* @param string $query
|
||||
* @param string $error
|
||||
* @param int $tdeb
|
||||
*/
|
||||
public function trace($query, $res='', $tdeb = null)
|
||||
{
|
||||
if ( $tdeb === null) {
|
||||
$duree = substr(''.microtime_float()-$tdeb, 0, 5);
|
||||
} else {
|
||||
$duree = 'N/D';
|
||||
}
|
||||
if ($this->errorCode == 0) {
|
||||
$msg = date('Y-m-d H:i:s') ." - DEBUG - ".$this->errorCode.":".$this->errorMsg." - ".$query." - ".$duree;
|
||||
} else {
|
||||
$msg = date('Y-m-d H:i:s') ." - ERROR - ".$this->errorCode.":".$this->errorMsg." - ".$query." - ".$duree;
|
||||
}
|
||||
file_put_contents(LOG_PATH . '/mysql.log', $msg . "\n", FILE_APPEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exécute la requête passé en paramètre
|
||||
*/
|
||||
public function query($query, $debug=false)
|
||||
{
|
||||
$this->errorCode = 0;
|
||||
$this->errorMsg = '';
|
||||
|
||||
try {
|
||||
$stmt = $this->db->query($query);
|
||||
$this->result = $stmt;
|
||||
} catch(Zend_Db_Exception $e) {
|
||||
$this->errorCode = $e->getCode();
|
||||
$this->errorMsg = $e->getMessage();
|
||||
$this->trace($query);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->result->fetchAll(Zend_Db::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/** Retourne le libellé de la dernière erreur **/
|
||||
public function getLastErrorMsg()
|
||||
{
|
||||
return $this->errorMsg;
|
||||
}
|
||||
/**
|
||||
* Retourne le numéro de la dernière erreur
|
||||
*/
|
||||
public function getLastErrorNum()
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
/** Retourne le libellé et le numéro de la dernière erreur **/
|
||||
public function getLastError()
|
||||
{
|
||||
return $this->errorMsg.' ('.$this->errorCode.')';
|
||||
}
|
||||
|
||||
/** Retourne le nombre de lignes modifiées par la dernière requête **/
|
||||
public function getAffectedRows()
|
||||
{
|
||||
return $this->result->rowCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Génère le fichier CSV pour la requete SQL
|
||||
*
|
||||
* @param string $query
|
||||
* @param string $fileCsv
|
||||
* @return bool
|
||||
*/
|
||||
public function exportCSV($query, $fileCsv, $sep=',', $eol=PHP_EOL)
|
||||
{
|
||||
$i = 0;
|
||||
$fp = fopen($fileCsv, 'w');
|
||||
if (!$fp) return false;
|
||||
|
||||
$res = $this->query($query);
|
||||
$nbLignes = count($res);
|
||||
for($i=0; $i<$nbLignes; $i++) {
|
||||
$ligne = $res[$i];
|
||||
|
||||
//Header
|
||||
if ($i==0) {
|
||||
$nbCols = count($ligne);
|
||||
$header = array();
|
||||
foreach ($ligne as $libCol => $col) {
|
||||
$header[] = $libCol;
|
||||
}
|
||||
fputcsv($fp, $header, $sep, '"');
|
||||
}
|
||||
|
||||
//Content
|
||||
$fields = array();
|
||||
foreach ($ligne as $libCol => $col) {
|
||||
$fields[] = $col;
|
||||
}
|
||||
fputcsv($fp, $fields, $sep, '"');
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
return $nbLignes;
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,431 +0,0 @@
|
||||
<?php
|
||||
|
||||
define ('BEFORE', 0);
|
||||
define ('AFTER', 1);
|
||||
define ('BOTH', 2);
|
||||
define ('ALIGN_LEFT', 0);
|
||||
define ('ALIGN_RIGHT', 1);
|
||||
|
||||
/**
|
||||
* Initialisation d'une chaîne de caractère
|
||||
* @param string $chaine
|
||||
* Chaîne de caractère initiale
|
||||
* @param int $taille
|
||||
* Taille de la chaîne de caractère à initialiser
|
||||
* @param string $caractere_pour_combler
|
||||
* Caractère à utiliser pour combler la chaîne de caractère (espace par défaut)
|
||||
* @param string $align
|
||||
* Aligner la chaîne de caractère à droite (right) ou à gauche (left, par défaut)
|
||||
* @return string
|
||||
*/
|
||||
function initstr($chaine, $taille, $caractere_pour_combler=' ', $align=ALIGN_LEFT)
|
||||
{
|
||||
if (mb_strlen($chaine) >= $taille) {
|
||||
return substr($chaine, 0, $taille);
|
||||
}
|
||||
|
||||
$encoding = mb_internal_encoding();
|
||||
$diff = strlen($chaine) - mb_strlen($chaine, $encoding);
|
||||
|
||||
if ($align == ALIGN_RIGHT) {
|
||||
return str_pad($chaine, $taille + $diff, $caractere_pour_combler, STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
if ($align == ALIGN_LEFT) {
|
||||
return str_pad($chaine, $taille + $diff, $caractere_pour_combler, STR_PAD_RIGHT);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajout d'anti-slashs s'il y a lieu en vu d'une insertion en BDD
|
||||
*
|
||||
* @param string $str Chaine de caractère
|
||||
* @return unknown
|
||||
*/
|
||||
|
||||
function checkaddslashes($str){
|
||||
return addslashes(preg_replace('/\\[^nrt\']/i', '\\', $str));
|
||||
}
|
||||
|
||||
function checkaddslashes2($str){
|
||||
if(strpos(str_replace("\'",''," $str"),"'")!=false)
|
||||
return addslashes($str);
|
||||
else
|
||||
return $str;
|
||||
}
|
||||
|
||||
function trimAccent ($strWithAccent) {
|
||||
$strWithAccent = htmlentities(strtolower($strWithAccent ));
|
||||
$strWithAccent = preg_replace("/&(.)(acute|cedil|circ|ring|tilde|uml|grave);/", "$1", $strWithAccent );
|
||||
$strWithAccent = preg_replace("/([^a-z0-9]+)/", " ", html_entity_decode($strWithAccent ));
|
||||
$strWithAccent = trim($strWithAccent , "-");
|
||||
return $strWithAccent;
|
||||
}
|
||||
|
||||
//function SRSaufVoyelle ($strIn, $mot1, $mot2) {
|
||||
function str_replace_except_voy($mot1, $mot2, $strIn, $rule=0) {
|
||||
$Voyelle=array('a','e','i','o','u','y', '1', '2', '3', '4');
|
||||
if ($mot1==$mot2) return $strIn;
|
||||
if (strpos($mot2,$mot1)===false)
|
||||
{
|
||||
//foreach ($Voyelle as $k => $voy)
|
||||
$posMot1=strpos($strIn, $mot1);
|
||||
while ($posMot1!==false) {
|
||||
$lettreAV=$strIn[$posMot1-1];
|
||||
$lettreAP=$strIn[$posMot1+strlen($mot1)];
|
||||
//echo "Lettre AV=$lettreAV<br/>";
|
||||
//echo "Lettre AP=$lettreAP<br/>";
|
||||
if ( ( $rule==0 && !in_array($lettreAV, $Voyelle) ) ||
|
||||
( $rule==1 && !in_array($lettreAP, $Voyelle) ) ||
|
||||
( $rule==2 && !in_array($lettreAV, $Voyelle) && !in_array($lettreAP, $Voyelle) ))
|
||||
$strIn=substr($strIn,0,$posMot1) . $mot2 . substr($strIn,$posMot1+strlen($mot1),strlen($strIn));
|
||||
//echo "Le Mot devient : $strIn<br/>";
|
||||
$posMot1=strpos($strIn, $mot1, $posMot1+strlen($mot1));
|
||||
}
|
||||
return $strIn;
|
||||
}
|
||||
//echo "Erreur : $mot2 contient $mot1 !<br>";
|
||||
return $strIn;
|
||||
}
|
||||
|
||||
/** Retourne le phonex d'un mot
|
||||
**/
|
||||
function phonex($strIn) {
|
||||
if ($strIn=='') return 0.0;
|
||||
$tabSonAIA=array('aina', 'eina', 'aima', 'eima');
|
||||
$tabSonAIE=array('ainr', 'eine', 'aime', 'eime');
|
||||
$tabSonAII=array('aini', 'eini', 'aimi', 'eimi');
|
||||
$tabSonAIO=array('aino', 'eino', 'aimo', 'eimo');
|
||||
$tabSonAIU=array('ainu', 'einu', 'aimu', 'eimu');
|
||||
$tabCarPhon=array('1', '2', '3', '4', '5', 'e', 'f', 'g', 'h', 'i', 'k', 'l', 'n', 'o', 'r', 's', 't', 'u', 'w', 'x', 'y', 'z');
|
||||
|
||||
/** On traite tout en minuscule **/
|
||||
$strIn=strtolower($strIn);
|
||||
/** On remplace les 'Y' par des 'I' **/
|
||||
$strIn=str_replace('y', 'i', $strIn);
|
||||
/** On supprime les accents **/
|
||||
$strIn=trimAccent($strIn);
|
||||
/** On retire les 'H' muets sauf ceux précédés par 'C' ou 'S' **/
|
||||
$strIn = preg_replace ('/(?<![CS])H/', '', $strIn);
|
||||
/** On remplace les 'PH' par des 'F' **/
|
||||
$strIn=str_replace('ph', 'f', $strIn);
|
||||
/** On remplace les 'G' par des 'K' devant AN AM AIN AIM **/
|
||||
$strIn=str_replace('gan', 'kan', $strIn);
|
||||
$strIn=str_replace('gain', 'kain', $strIn);
|
||||
$strIn=str_replace('gam', 'kam4', $strIn);
|
||||
$strIn=str_replace('gaim', 'kaim', $strIn);
|
||||
/** On remplace le son AI **/
|
||||
for ($i=0; $i>4; $i++) {
|
||||
$strIn=str_replace($tabSonAIA[$i], 'yna', $strIn);
|
||||
$strIn=str_replace($tabSonAIE[$i], 'yne', $strIn);
|
||||
$strIn=str_replace($tabSonAII[$i], 'yni', $strIn);
|
||||
$strIn=str_replace($tabSonAIO[$i], 'yno', $strIn);
|
||||
$strIn=str_replace($tabSonAIU[$i], 'ynu', $strIn);
|
||||
}
|
||||
/** Remplacement des groupes de 3 lettres **/
|
||||
$strIn=str_replace('eau', 'o', $strIn);
|
||||
$strIn=str_replace('oua', '2', $strIn);
|
||||
$strIn=str_replace('ein', '4', $strIn);
|
||||
$strIn=str_replace('ain', '4', $strIn);
|
||||
/** Remplacement du son 'é' **/
|
||||
$strIn=str_replace('ai', 'y', $strIn);
|
||||
$strIn=str_replace('ei', 'y', $strIn);
|
||||
$strIn=str_replace('er', 'yr', $strIn);
|
||||
$strIn=str_replace('ess', 'yss', $strIn);
|
||||
$strIn=str_replace('et', 'yt', $strIn);
|
||||
$strIn=str_replace('ez', 'yz', $strIn);
|
||||
/** Remplacement des groupes de 2 lettres sauf si voyelle ou son (1 à 4) AVANT **/
|
||||
$strIn=str_replace_except_voy('an', '1', $strIn, BEFORE);
|
||||
$strIn=str_replace_except_voy('am', '1', $strIn, BEFORE);
|
||||
$strIn=str_replace_except_voy('en', '1', $strIn, BEFORE);
|
||||
$strIn=str_replace_except_voy('em', '1', $strIn, BEFORE);
|
||||
$strIn=str_replace_except_voy('in', '4', $strIn, BEFORE);
|
||||
/** Remplacement du son 'SCH' **/
|
||||
$strIn=str_replace('sch', '5', $strIn);
|
||||
/** Remplacement du 'S' sauf si voyelle ou son (1 à 4) avant ou après **/
|
||||
$strIn=str_replace_except_voy('in', '4', $strIn, BOTH);
|
||||
/** Remplacement de groupe de 2 lettres diverses **/
|
||||
$strIn=str_replace('oe', 'e', $strIn);
|
||||
$strIn=str_replace('eu', 'e', $strIn);
|
||||
$strIn=str_replace('au', 'o', $strIn);
|
||||
$strIn=str_replace('oi', '2', $strIn);
|
||||
$strIn=str_replace('oy', '2', $strIn);
|
||||
$strIn=str_replace('ou', '3', $strIn);
|
||||
$strIn=str_replace('ch', '5', $strIn);
|
||||
$strIn=str_replace('sh', '5', $strIn);
|
||||
$strIn=str_replace('ss', 's', $strIn);
|
||||
$strIn=str_replace('sc', 's', $strIn);
|
||||
/** Remplacement du 'C' par 'S' s'il est suivi d'un 'E' ou d'un 'I' **/
|
||||
$strIn=str_replace('ce', 'se', $strIn);
|
||||
$strIn=str_replace('ci', 'si', $strIn);
|
||||
/** Remplacement divers **/
|
||||
$strIn=str_replace('c', 'k', $strIn);
|
||||
$strIn=str_replace('q', 'k', $strIn);
|
||||
$strIn=str_replace('qu', 'k', $strIn);
|
||||
|
||||
$strIn=str_replace('ga', 'ka', $strIn);
|
||||
$strIn=str_replace('go', 'ko', $strIn);
|
||||
$strIn=str_replace('gu', 'ku', $strIn);
|
||||
$strIn=str_replace('gy', 'ky', $strIn);
|
||||
$strIn=str_replace('g2', 'k2', $strIn);
|
||||
$strIn=str_replace('g1', 'k1', $strIn);
|
||||
$strIn=str_replace('g3', 'k3', $strIn);
|
||||
|
||||
$strIn=str_replace('a', 'o', $strIn);
|
||||
$strIn=str_replace('d', 't', $strIn);
|
||||
$strIn=str_replace('p', 't', $strIn);
|
||||
$strIn=str_replace('j', 'g', $strIn);
|
||||
$strIn=str_replace('b', 'f', $strIn);
|
||||
$strIn=str_replace('v', 'f', $strIn);
|
||||
$strIn=str_replace('m', 'n', $strIn);
|
||||
|
||||
/** Supression des lettres dupliquées **/
|
||||
$let=$strIn[0];
|
||||
$strIn2=$let;
|
||||
for ($i=1; $i<strlen($strIn); $i++)
|
||||
{ if ($strIn==$let)
|
||||
continue;
|
||||
else {
|
||||
$let=$strIn[$i];
|
||||
$strIn2.=$strIn[$i];
|
||||
}
|
||||
}
|
||||
$strIn=$strIn2;
|
||||
|
||||
/** Supression des terminaisons **/
|
||||
$strIn2=substr($strIn,-1);
|
||||
if ($strIn2=='t' || $strIn2=='k' || $strIn2=='s' || $strIn2=='z')
|
||||
$strIn=substr($strIn,0,-1);
|
||||
|
||||
/** Supression des caractères non autorisés **/
|
||||
$j=10;
|
||||
$sout=array();
|
||||
for ($i=0; $i<strlen($strIn); $i++)
|
||||
{
|
||||
if ($j<1) break;
|
||||
for ($k=0; $k<22; $k++)
|
||||
{
|
||||
if ($strIn[$i]==$tabCarPhon[$k])
|
||||
{
|
||||
$sout[$j]=$k;
|
||||
$j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
print_r($tabCarPhon);
|
||||
|
||||
/** Couversion en flottant **/
|
||||
$result=0.0;
|
||||
for ($j=10; $j>0; $j--)
|
||||
$result+=$sout[$j]*pow($j-1,10);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* CLASS soundex2
|
||||
* soundex2 French version
|
||||
* based on the algorithm described here : http://sqlpro.developpez.com/cours/soundex/ by Frédéric BROUARD
|
||||
*
|
||||
* author Johan Barbier <barbier_johan@hotmail.com>
|
||||
*/
|
||||
class csoundex2 {
|
||||
|
||||
/**
|
||||
* public sString
|
||||
* main string we work on
|
||||
*/
|
||||
var $sString = '';
|
||||
|
||||
/**
|
||||
* vowels replacement array
|
||||
*/
|
||||
var $aReplaceVoy1 = array (
|
||||
'E' => 'A',
|
||||
'I' => 'A',
|
||||
'O' => 'A',
|
||||
'U' => 'A'
|
||||
);
|
||||
|
||||
/**
|
||||
* consonnants replacement array
|
||||
*/
|
||||
var $aReplaceGrp1 = array (
|
||||
'GUI' => 'KI',
|
||||
'GUE' => 'KE',
|
||||
'GA' => 'KA',
|
||||
'GO' => 'KO',
|
||||
'GU' => 'K',
|
||||
'CA' => 'KA',
|
||||
'CO' => 'KO',
|
||||
'CU' => 'KU',
|
||||
'Q' => 'K',
|
||||
'CC' => 'K',
|
||||
'CK' => 'K'
|
||||
);
|
||||
|
||||
/**
|
||||
* other replacement array
|
||||
*/
|
||||
var $aReplaceGrp2 = array (
|
||||
'ASA' => 'AZA',
|
||||
'KN' => 'NN',
|
||||
'PF' => 'FF',
|
||||
'PH' => 'FF',
|
||||
'SCH' => 'SSS'
|
||||
);
|
||||
|
||||
/**
|
||||
* endings replacement array
|
||||
*/
|
||||
var $aEnd = array (
|
||||
'A',
|
||||
'T',
|
||||
'D',
|
||||
'S'
|
||||
);
|
||||
|
||||
/**
|
||||
* public function build
|
||||
* core function of the class, go through the whole process
|
||||
* @Param string sString : the string we want to check
|
||||
*/
|
||||
function build ($sString) {
|
||||
/**
|
||||
* let's check it's a real string...
|
||||
*/
|
||||
if (is_string ($sString) && !empty ($sString)) {
|
||||
$this -> sString = $sString;
|
||||
} else {
|
||||
trigger_error ('Parameter string must not be empty', E_USER_ERROR);
|
||||
}
|
||||
/**
|
||||
* remove starting and ending spaces
|
||||
*/
|
||||
$this -> sString = trim ($this -> sString);
|
||||
/**
|
||||
* remove special french characters
|
||||
*/
|
||||
$this -> trimAccent ();
|
||||
/**
|
||||
* string to upper case
|
||||
*/
|
||||
$this -> sString = strtoupper ($this -> sString );
|
||||
/**
|
||||
* let's remove every space in the string
|
||||
*/
|
||||
$this -> sString = str_replace (' ', '', $this -> sString);
|
||||
/**
|
||||
* let's remove every '-' in the string
|
||||
*/
|
||||
$this -> sString = str_replace ('-', '', $this -> sString);
|
||||
/**
|
||||
* let's process through the first replacement array
|
||||
*/
|
||||
$this -> arrReplace ($this -> aReplaceGrp1);
|
||||
/**
|
||||
* let's process through th vowels replacement
|
||||
*/
|
||||
$sChar = substr ($this -> sString, 0, 1);
|
||||
$this -> sString = substr ($this -> sString, 1, strlen ($this -> sString) - 1);
|
||||
$this -> arrReplace ($this -> aReplaceVoy1);
|
||||
$this -> sString = $sChar.$this -> sString;
|
||||
/**
|
||||
* let's process through the second replacement array
|
||||
*/
|
||||
$this -> arrReplace ($this -> aReplaceGrp2, true);
|
||||
/**
|
||||
* let's remove every 'H' but those prededed by a 'C' or an 'S'
|
||||
*/
|
||||
$this -> sString = preg_replace ('/(?<![CS])H/', '', $this -> sString);
|
||||
/**
|
||||
* let's remove every 'Y' but those preceded by an 'A'
|
||||
*/
|
||||
$this -> sString = preg_replace ('/(?<!A)Y/', '', $this -> sString);
|
||||
/**
|
||||
* remove endings in aEnd
|
||||
*/
|
||||
$length = strlen ($this -> sString) - 1;
|
||||
if (in_array ($this -> sString{$length}, $this -> aEnd)) {
|
||||
$this -> sString = substr ($this -> sString, 0, $length);
|
||||
}
|
||||
/**
|
||||
* let's remove every 'A', but the one at the beginning of the string, if any.
|
||||
*/
|
||||
$sChar = '';
|
||||
if ($this -> sString{0} === 'A') {
|
||||
$sChar = 'A';
|
||||
}
|
||||
$this -> sString = str_replace ('A', '', $this -> sString);
|
||||
$this -> sString = $sChar.$this -> sString;
|
||||
/**
|
||||
* let's have only 1 occurence of each letter
|
||||
*/
|
||||
$this -> sString = preg_replace( '/(.)\1/', '$1', $this -> sString );
|
||||
/**
|
||||
* let's have the final code : a 4 letters string
|
||||
*/
|
||||
$this -> getFinal ();
|
||||
}
|
||||
|
||||
/**
|
||||
* private function getFinal
|
||||
* gets the first 4 letters, pads the string with white space if the string length < 4
|
||||
*/
|
||||
function getFinal () {
|
||||
if (strlen ($this -> sString) < 4) {
|
||||
$this -> sString = str_pad ($this -> sString, 4, ' ', STR_PAD_RIGHT);
|
||||
} else {
|
||||
$this -> sString = substr ($this -> sString, 0, 4);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* private function trimAccent
|
||||
* remove every special French letters
|
||||
*/
|
||||
function trimAccent () {
|
||||
$this -> sString = htmlentities(strtolower($this -> sString ));
|
||||
$this -> sString = preg_replace("/&(.)(acute|cedil|circ|ring|tilde|uml|grave);/", "$1", $this -> sString );
|
||||
$this -> sString = preg_replace("/([^a-z0-9]+)/", "-", html_entity_decode($this -> sString ));
|
||||
$this -> sString = trim($this -> sString , "-");
|
||||
}
|
||||
|
||||
/**
|
||||
* private function arrReplace
|
||||
* replacement method, given an array
|
||||
* @Param array tab : the replacement array to be used
|
||||
* @Param bool pref : if false, just replace keys by values; if true, do the same but only with prefix
|
||||
*/
|
||||
function arrReplace (array $tab, $pref = false) {
|
||||
$fromRep = array_keys ($tab);
|
||||
$toRep = array_values ($tab);
|
||||
if (false === $pref) {
|
||||
$this -> sString = str_replace ($fromRep, $toRep, $this -> sString);
|
||||
} else {
|
||||
foreach ($fromRep as $clef => $val) {
|
||||
$length = strlen ($val);
|
||||
if (substr ($this -> sString, 0, $length) === $val) {
|
||||
$this -> sString = substr_replace ($this -> sString, $toRep[$clef], 0, $length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function soundex2($str) {
|
||||
$soundex2 = new csoundex2();
|
||||
|
||||
$soundex2 -> build ($str);
|
||||
return $soundex2 -> sString;
|
||||
}
|
||||
|
||||
function htm2txt($str) {
|
||||
return trim(strip_tags( str_replace(chr(160), ' ',
|
||||
str_replace('œ', 'oe',
|
||||
str_replace('’', '\'', html_entity_decode($str, ENT_QUOTES))))));
|
||||
}
|
||||
?>
|
@ -1,104 +1,7 @@
|
||||
<?php
|
||||
require_once 'framework/common/mysql.php';
|
||||
require_once 'framework/common/strings.php';
|
||||
require_once 'framework/common/dates.php';
|
||||
|
||||
/** TimeStamp Unix
|
||||
** Si $onlyMiliSec=true, retourne juste les milisec du timestamp
|
||||
**/
|
||||
function microtime_float($onlyMiliSec=false)
|
||||
{
|
||||
list($usec, $sec) = explode(' ', microtime());
|
||||
if (!$onlyMiliSec) {
|
||||
return ((float)$usec + (float)$sec);
|
||||
} else {
|
||||
return $usec;
|
||||
}
|
||||
}
|
||||
|
||||
/** Fait une pause aléatoire entre 0 et 15 secondes par défaut
|
||||
**/
|
||||
function randsleep($min_sec=0, $max_sec=15)
|
||||
{
|
||||
sleep(rand($min_sec, $max_sec));
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérification que la variable demandé respecte bien les règles passées en paramètres
|
||||
* @param mixed Variable à tester
|
||||
* @param int Longueur minimum en caractère de la variable
|
||||
* @param int Longueur mximum
|
||||
* @param char(1) Type de variable <b>A</b>:Alphanumérique / <b>N</b>:Numérique
|
||||
* @param mixed Message textuel d'erreur à afficher en cas d'erreur ou false
|
||||
* @return mixed true, false ou Message d'erreur passé en paramètre
|
||||
*/
|
||||
function valideData($variable, $taille_min, $taille_max, $type_variable, $erreur=false) {
|
||||
if ( strlen((string)$variable) < $taille_min )
|
||||
return $erreur;
|
||||
|
||||
if ( strlen((string)$variable) > $taille_max )
|
||||
return $erreur;
|
||||
|
||||
if ( $type_variable == 'A' )
|
||||
if ( is_string($variable) == true )
|
||||
return true;
|
||||
else
|
||||
return $erreur;
|
||||
|
||||
elseif ( $type_variable == 'N')
|
||||
{
|
||||
for ($i=0; $i < strlen((string)$variable); $i++)
|
||||
{
|
||||
$car = substr((string)$variable,$i,1);
|
||||
if ($car<'0' || $car>'9')
|
||||
return $erreur;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return $erreur;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enregistrer une information dans la log
|
||||
* @param string $debugLevel E=Error, W=Warning, N=Notice, I=Info, D=Debug
|
||||
* @param string $message Message d'erreur à inscrire dans la log
|
||||
* @param integer $line __LINE__
|
||||
* @param string $file __FILE__
|
||||
* @param string $function __FUNCTION__
|
||||
* @param string $class __CLASS___
|
||||
*/
|
||||
function debugLog($debugLevel, $message, $line, $file, $function, $class)
|
||||
{
|
||||
if ($debugLevel=='E'){
|
||||
if (!file_exists(LOG_PATH.'/debugError.log')) {
|
||||
file_put_contents(LOG_PATH.'/debugError.log', 'Date/Heure;Niveau;Script;Login;Password;Adresse IP;Action SOAP;Ligne;Fichier;Fonction;Classe;Domaine;POST DATA;Message'.PHP_EOL);
|
||||
} else {
|
||||
file_put_contents(LOG_PATH.'/debugError.log', date('Y/m/d-H:i:s') .';'. $debugLevel .';'. $_SERVER['PHP_SELF'] .';'. $_SERVER['PHP_AUTH_USER'] .';'. $_SERVER['PHP_AUTH_PW'] .';'.
|
||||
$_SERVER['REMOTE_ADDR'] .';'. $_SERVER['HTTP_SOAPACTION'] .';'.$line.';'. $file.';'. $function.';'. $class .';'.
|
||||
@gethostbyaddr($_SERVER['REMOTE_ADDR']) .';'. $HTTP_RAW_POST_DATA .';'. @memory_get_usage().';'. $message . PHP_EOL, FILE_APPEND);
|
||||
}
|
||||
} else {
|
||||
if (!file_exists(LOG_PATH.'/debug.log')) {
|
||||
file_put_contents(LOG_PATH.'/debug.log', 'Date/Heure;Niveau;Script;Login;Password;Adresse IP;Action SOAP;Ligne;Fichier;Fonction;Classe;Domaine;POST DATA;Memory;Message'.PHP_EOL);
|
||||
} else {
|
||||
file_put_contents(LOG_PATH.'/debug.log',
|
||||
date('Y/m/d-H:i:s') .';'. $debugLevel .';'. $_SERVER['PHP_SELF'] .';'. $_SERVER['PHP_AUTH_USER'] .';'.
|
||||
$_SERVER['PHP_AUTH_PW'] .';'. $_SERVER['REMOTE_ADDR'] .';'. $_SERVER['HTTP_SOAPACTION'] .';'.
|
||||
$line.';'. $file.';'. $function.';'. $class .';'. @gethostbyaddr($_SERVER['REMOTE_ADDR']) .';'.
|
||||
$HTTP_RAW_POST_DATA .';'. @memory_get_usage().';'. $message . PHP_EOL, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A SUPPRIMER
|
||||
function prepareString($str) {
|
||||
$tabReplace = array(
|
||||
'œ' => "oe",
|
||||
''.chr(160) => '',
|
||||
);
|
||||
|
||||
$str = utf8_decode($str);
|
||||
$str = strtr($str,$tabReplace);
|
||||
return utf8_encode($str);
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @param unknown $from
|
||||
* @param unknown $to
|
||||
* @param unknown $subject
|
||||
* @param string $text
|
||||
* @param string $html
|
||||
* @param unknown $tabAttachedFiles
|
||||
*/
|
||||
function sendMail($from, $to, $subject, $text='', $html='', $tabAttachedFiles=array())
|
||||
{
|
||||
$to = preg_split("/[\s,;]+/", $to);
|
||||
|
||||
$mail = new Scores_Mail_Method();
|
||||
$mail->setFrom($from);
|
||||
if ( count($to) > 0 ) {
|
||||
foreach ( $to as $item ) {
|
||||
$mail->addTo($item);
|
||||
}
|
||||
}
|
||||
$mail->setSubject($subject);
|
||||
if ($text!='') {
|
||||
$mail->setBodyText($text);
|
||||
}
|
||||
|
||||
if ($html!='') {
|
||||
$mail->setBodyHtml($html);
|
||||
}
|
||||
|
||||
if ( count($tabAttachedFiles) > 0 ) {
|
||||
foreach ($tabAttachedFiles as $file) {
|
||||
$at = new Zend_Mime_Part( file_get_contents( $file ) );
|
||||
$mail->addAttachment($at);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$mail->execute();
|
||||
} catch (Zend_Mail_Transport_Exception $e) {
|
||||
file_put_contents(LOG_PATH.'/sendMailError.log', date('Y-m-d H:i:s')." - ".$e->getMessage()."\n", FILE_APPEND);
|
||||
} catch (Zend_Mail_Protocol_Exception $e) {
|
||||
file_put_contents(LOG_PATH.'/sendMailError.log', date('Y-m-d H:i:s')." - ".$e->getMessage()."\n", FILE_APPEND);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user