<?php
include_once("../../fonctions.php");
loadgsm7arrs();
mysql_connect($ServeurSQL,$Login,$Password) or die("Erreur de Connection : <b>".mysql_error());
mysql_select_db($Base) or die("Impossible de se connecter a la base de donnees");
$message_smsc_id = $message_smsc_taille = '0';
# nombre de MO sur le jeu de redirection ($game_redir_id) du kiosque $DA
$sql = "
SELECT
`SOA` AS telephone,
`Content` AS message,
SUBSTRING(Content,1,2) AS flags_first_car,
SUBSTRING(Content,5,2) AS flags_nbre_follow,
DATE_FORMAT(`mo_dateReceived`,'%d/%m% %H:%i') AS date,
DATE_FORMAT(`mo_dateReceived`,'%Y') AS Y,
DATE_FORMAT(`mo_dateReceived`,'%m') AS m,
DATE_FORMAT(`mo_dateReceived`,'%d') AS d,
DATE_FORMAT(`mo_dateReceived`,'%H') AS H,
DATE_FORMAT(`mo_dateReceived`,'%i') AS i,
DATE_FORMAT(`mo_dateReceived`,'%s') AS s,
`smg_mo`.`mo_id` AS id,
`smg_players_history`.`won` AS won ,
`Flags`, `TimeCreated`
FROM `smg_mo`
JOIN `smg_players_history`
ON `smg_players_history`.`mo_id` = `smg_mo`.`mo_id`
WHERE `smg_mo`.`mo_archived` = '0'
AND `smg_mo`.`mo_deleted` = '0'
AND `smg_mo`.`DA` = '$DA'
AND `smg_players_history`.`game_id` = '$game_redir_id'
ORDER BY `TimeCreated` ASC, telephone ASC
";
$result = mysql_query($sql) or die ('Erreur : '.mysql_error() );
$total = mysql_num_rows($result);
mysql_free_result($result);
if($total) {
while($row = mysql_fetch_assoc($result)) {
$telephone = $row['telephone'];
$TimeCreated = $row['TimeCreated'];
$Flags = $row['Flags'];
// si message en clair
if ( $Flags=="131084" || $Flags=="131076" || $Flags=="139264" || $Flags=="147724" || $Flags=="147716" || $Flags=="131092" || $Flags=="131264" || $Flags=="131072" || $Flags=="147712" ) {
$message_displayed = $row['message'];
}
// Assomption Nico : la date de creation des differentes parties suivantes doit etre inférieure à celle du 1er message + 1 minute
# $TimeCreated_min = date( 'Y-m-d H:i:s',mktime ($row['H'],$row['i']-1,$row['s'],$row['m'],$row['d'],$row['Y']) );
$TimeCreated_max = date( 'Y-m-d H:i:s',mktime ($row['H'],$row['i']+1,$row['s'],$row['m'],$row['d'],$row['Y']) );
$tel = str_split($row['telephone'], 2);
// 1er hexa du header (UDH lengh)
$flags_udh_lengh = $row['flags_first_car'];
// nbre de caracteres du header
$flags_lengh = $flags_udh_lengh*2+2;
// nombre de caracteres restants pour le message
$message_lengh = strlen(substr($row['message'],$flags_lengh));
// nombre parties suivantes du header
$flags_nbre_follow = $row['flags_nbre_follow'];
// nombre de parties du messages
$message_part_nbre = (int) ( substr($row['message'],4+$flags_nbre_follow*2-2,2) );
// numero partie message
$message_part_id = (int) ( substr($row['message'],4+$flags_nbre_follow*2,2) );
// message id SMSC
if ( $flags_nbre_follow == "03" ) { $message_smsc_taille = "2"; $header_lengh = "12"; }
if ( $flags_nbre_follow == "04" ) { $message_smsc_taille = "4"; $header_lengh = "14"; }
if ( isset($message_smsc_taille) ) {
$message_smsc_id = substr( $row['message'],6 , $message_smsc_taille );
}
// si UCS2
if ( ($Flags=="217344" || $Flags=="217356") && ($flags_udh_lengh=="05" || $flags_udh_lengh=="06") ) {
// si le nombre de caracteres restants (sans compter le UDH) du message est impair, enlever le dernier caractere
if ( $message_lengh&1 ) {
$message_displayed = substr( ucs2ToStr( substr($row['message'],$flags_lengh) ),0,-1);
}
else {
// conversion ucs2 du message sans le UDH
$message_displayed = ucs2ToStr( substr($row['message'],$flags_lengh) );
}
}
// si encodage 7bits
if ( $Flags=="200704" ) {
if ( $flags_udh_lengh%2 == 1 ) { $pad=1; } else { $pad=0; }
if ( $flags_udh_lengh=="05" || $flags_udh_lengh=="06" ) {
$message_displayed = pdu2asc( substr($row['message'],hexdec($flags_lengh)), $pad);
}
if ( ( $flags_udh_lengh=="09" || $flags_udh_lengh=="0A" ) && $flags_nbre_follow=="04" ) {
$message_displayed = substr(pdu2asc( substr($row['message'],$header_lengh), 0),$message_smsc_taille);
}
if ( $flags_udh_lengh=="0B" && $flags_nbre_follow=="04" ) {
$message_displayed = substr(pdu2asc( substr($row['message'],$header_lengh), 0),6);
}
if ( $flags_udh_lengh=="08" && $flags_nbre_follow=="03" ) {
$message_displayed = substr(pdu2asc( substr($row['message'],$header_lengh), 1),4);
}
if ( $flags_udh_lengh=="0A" && $flags_nbre_follow=="03" ) {
$message_displayed = substr(pdu2asc( substr($row['message'],$header_lengh), 1),6);
}
if ( $flags_udh_lengh=="04" && $flags_nbre_follow=="02" ) {
$message_displayed = pdu2asc( substr($row['message'],12), 1);
}
if ( $flags_udh_lengh=="0F" && $flags_nbre_follow=="03" ) {
$message_displayed = substr(pdu2asc( substr($row['message'],$header_lengh), 1),$header_lengh);
}
if ( substr($row['message'],0,8)=="03240101" || substr($row['message'],0,8)=="03250101" ) {
$message_displayed = "<b>Décodé: </b>".pdu2asc( substr($row['message'],12), $pad);
}
else {
$message_displayed = pdu2asc( substr($row['message'],$header_lengh), $pad );
}
}
if ( $Flags=="200716" ) {
if ( $flags_udh_lengh%2 == 1 ) { $pad=1; } else { $pad=0; }
if ( $flags_udh_lengh=="05" || $flags_udh_lengh=="06" ) {
$message_displayed = pdu2asc( substr($row['message'],hexdec($flags_lengh)), $pad);
}
else {
$message_displayed = pdu2asc( substr($row['message'],$header_lengh), $pad );
}
}
if ( $Flags <> "131072" ) {
// creation d'un tableau par numero de telephone
${"$telephone"}[] = array('id'=>$row['id'], 'time'=>$TimeCreated, 'parts'=>$message_part_nbre, 'part'=>$message_part_id, 'smsc_id'=>$message_smsc_id, 'message'=>$message_displayed, 'flags'=>$Flags);
// mise en forme du tableau en colonnes pour trier avec array_multisort
foreach (${"$telephone"} as $cle => $col) {
$id[$cle] = $col['id'];
$time[$cle] = $col['time'];
$parts[$cle] = $col['parts'];
$part[$cle] = $col['part'];
$smsc_id[$cle] = $col['smsc_id'];
$message[$cle] = $col['message'];
$flags[$cle] = $col['flags'];
}
// tri du tableau : les différentes parties du messages multipart sont dans l'ordre
array_multisort( $flags, SORT_ASC, $smsc_id, SORT_ASC, $parts, SORT_ASC, $part, SORT_ASC, $time, SORT_ASC, ${"$telephone"});
}
// creation d'un tableau pour la liste des messages a afficher
$messages[$row['id']] = array('id'=>$row['id'], 'time'=>$TimeCreated, 'time_max'=>$TimeCreated_max, 'tel'=>$telephone, 'parts'=>$message_part_nbre, 'part'=>$message_part_id, 'smsc_id'=>$message_smsc_id, 'message'=>$message_displayed, 'message_lengh'=>$message_lengh, 'flags'=>$Flags, 'flags_udh_lengh'=>$flags_udh_lengh, 'flags_lengh'=>$flags_lengh, 'remove'=>NULL, 'message_org'=>$row['message'], 'won'=>$row['won'], 'date_received'=>$row['date']);
} // fin while
} // fin if total
// assemblage des differentes parties du multipart : parcours des tableaux messages et telephone, assemblage si correspondance
$remove = array();
foreach ($messages as $key => $ligne) {
foreach ($ligne as $key1 => $val) {
// si message multipart
if ( $key1=='parts' && $val>"1") {
# echo $key1."=".$val."<br>";
foreach ( ${$messages[$key]['tel']} as $key2 => $ligne2 ) {
if ( ${$messages[$key]['tel']}[$key2]['time']<$messages[$key]['time_max'] && ${$messages[$key]['tel']}[$key2]['parts']==$messages[$key]['parts'] && ${$messages[$key]['tel']}[$key2]['smsc_id']==$messages[$key]['smsc_id'] && ${$messages[$key]['tel']}[$key2]['flags']==$messages[$key]['flags'] && ${$messages[$key]['tel']}[$key2]['part']>$messages[$key]['part'] ) {
$messages[$key]['message'] .= ${$messages[$key]['tel']}[$key2]['message'];
$messages[$key]['remove'] .= ' '.${$messages[$key]['tel']}[$key2]['id'];
$messages[$key]['id'] .= ' '.${$messages[$key]['tel']}[$key2]['id'];
// creation tableau $remove avec la liste des messages a supprimer
$remove[${$messages[$key]['tel']}[$key2]['id']] = ${$messages[$key]['tel']}[$key2]['id'];
} // fin foreach
}
// suppression des parties inutiles
if (array_key_exists($key, $remove)) {
unset ( $messages[$key] );
unset ( $remove[$key] );
}
} // fin si message multipart
}
}
// affichage des parties re-assemblees
foreach ($messages as $key => $ligne) {
echo '
<tr>
<td class="row1" nowrap="nowrap"><input type="checkbox" name="archive[]" value="'.$messages[$key]['id'].'" /><span class="gensmall">A</span></td>
<td class="row2" align="center" valign="middle" nowrap="nowrap"><span class="gensmall">'.$messages[$key]['date_received'].'</span></td>
<td class="row2" align="center" valign="middle" nowrap="nowrap"><span class="gensmall">'.substr($messages[$key]['tel'],3,6).'</span></td>
<td align="left" valign="middle" bgcolor="white"><span class="gen">';
if ( $messages[$key]['parts'] > "1" ) {
echo '<b>Décodé: </b>';
}
if ( $messages[$key]['won'] == "1" ) { echo '<b>';}
echo $messages[$key]['message'];
if ( $messages[$key]['won'] == "1" ) { echo '</b>';}
if ( $messages[$key]['parts'] > "1" && strlen($messages[$key]['message']) > 160 ) {
echo ' <i>('.$messages[$key]['parts'].' SMS : '.strlen($messages[$key]['message']).' caractères)</i>';
}
if ( $messages[$key]['parts'] > "1" && strlen($messages[$key]['message']) < 160 ) {
$part = explode ( " ",$messages[$key]['id'] );
echo ' <i>('.count($part).' SMS)</i>';
}
echo '</span></td>';;
echo'
<td class="row1" nowrap="nowrap"><input type="checkbox" name="delete[]" value="'.$messages[$key]['id'].'" /><span class="gensmall">S</span></td>
</tr>
';
}
Add a code snippet to your website: www.paste.org