FrameBeurk File
Fmbk/Module/Kom1/helpersMajKom1.php
<?php //FrameBeurk V0.65 Copyright ToolOscope 2016. Licence CeCILL-C.
// affiche la div qui contiendra le(s) erreur(s) sur le form
function Kom1_formateDivErreur($forceMessage = false) {
global $TRANSAC;
return '<div id="err' . $TRANSAC['Vue']['DivNormale'] . ((isset($TRANSAC['Maj']) && $TRANSAC['Maj']['Erreur'] || $forceMessage) ? ('">' . $TRANSAC['Message']['Maj']) : '" style="display:none;">')
. '</div>';
}
//affichage d'un formulaire de saisie
//$IdRef alimenté pour les créations.
//la fonction de callback permet de rajouter des champs en saisie après le champ Donnees
function Kom1_carteMajEntite($ActMaj, $IdMaj, $callbackFunc = '', $callbackParam = array(), $titreObj = '', $donneesObj = '', $IdRef = '') {
global $TRANSAC, $CONFIG;
$TRANSAC['Page']['ForceTabIndex'] = true; // force l'utilisation des tabIndex pour éviter que les select de BBCodes ne soient avant les données
$IdMaj = Beurk_id($IdMaj);
echo Beurk_divAccueil(array('ActVue' => 'previsualise', 'IdVue' => $IdMaj), 'inPopUp'),
'<form id="', $TRANSAC['Vue']['Form'], '" class="saisieVue" action="', Kom1_urlReafficheSite(), '" method="post" enctype="', $TRANSAC['Page']['Enctype'], '">
', Kom1_formateDivErreur(), '
', Beurk_fieldset (Beurk_message('Titre', 'Kom1'), Beurk_baliseInput('text', "titre$IdMaj", $titreObj, '', '', 80)),
Kom1_formateDivBBcodes($ActMaj, $IdMaj),
Beurk_fieldset (Beurk_message('Contenu', 'Kom1'), Beurk_baliseTextarea("donnees$IdMaj", $donneesObj, '', 'virtual')),
(($callbackFunc != '') ? $callbackFunc($ActMaj, $IdMaj, $callbackParam) : ''),
Kom1_formateValidation($ActMaj, $IdMaj, Beurk_traduit('votre entrée', 'Kom1'), (! $CONFIG['Module']['Kom1']['Fonctions']['EstLogue']()), true),
(($IdRef != '') ? '<input type="hidden" name="IdRef" value="' . $IdRef . '">' : ''), '
</form>
';
}
// callback à la fonction précédente : saisie d'un champ d'import, pour l'admin uniquement
function Kom1_carteMajEntiteCallbackImport($ActMaj, $IdMaj, $callbackParam) {
global $CONFIG;
if ($CONFIG['Module']['Kom1']['Fonctions']['EstAdmin']() && isset($callbackParam['Import']))
echo '
', Beurk_fieldset ('Import', Beurk_baliseInput('text', "import$IdMaj", $callbackParam['Import'], '', '', 80));
}
// validation d'une saisie avec ou sans somme de contrôle
function Kom1_formateValidation($ActMaj, $IdMaj, $libelle, $topSommeControle, $topPrevisu, $actionReinit = '') {
global $TRANSAC, $DIALOG;
$validForm = '';
if ($topSommeControle) {
$nombre1 = rand(1, 10);
$nombre2 = rand(1, 10);
$validForm = '<fieldset>
<legend>' . Beurk_traduit('Validation', 'Kom1') . ' :</legend>
<label>' . Beurk_traduit('Pour valider %s', 'Kom1', $libelle) . ' : ' . Beurk_traduit('Combien font ', 'Kom1') . Kom1_SecImage($nombre1 . ' + ' . $nombre2 . ' ?') . '
<input type="text" name="sommeControle" class="enligne" size="2" maxlength="2"' . Beurk_tabIndex() . '>
</label>
</fieldset>
';
$DIALOG['Somme'][ $ActMaj . Beurk_id($IdMaj) ] = $nombre1 + $nombre2; // sauvegarde en dialogue du résultat attendu
}
$validForm .= '<div>
';
if ($topPrevisu)
$validForm .= '<input type="button" value="' . Beurk_traduit('Prévisualiser', 'Kom1') . '" data-previsu="' . $TRANSAC['Vue']['Form'] . '/' . $IdMaj . '" ' . Beurk_tabIndex() . ">\n";
// data-ajax : "chargement" dans $TRANSAC['Vue']['DivNormale'] / recharger la page si Maj OK /
return $validForm .
'<input type="submit" value="' . Beurk_traduit('Envoyer', 'Kom1') . '" data-ajax="' . $TRANSAC['Vue']['DivNormale'] . '/Page/' . $TRANSAC['Vue']['DivNormale'] . '"' . Beurk_tabIndex() . '>
<input type="reset" value="' . Beurk_traduit('Réinitialiser', 'Kom1') . '"' . Beurk_tabIndex() . (($actionReinit != '') ? (' onClick="' . $actionReinit . '"') : '') . '>
<input type="button" value="' . Beurk_traduit('Annuler', 'Kom1') . '" data-cache="' . $TRANSAC['Vue']['DivNormale'] . '" ' . Beurk_tabIndex() . '>
' . Beurk_baliseInput('hidden', 'ActMaj', $ActMaj) . '
' . Beurk_baliseInput('hidden', 'IdMaj', $IdMaj) . '
<input type="hidden" name="JetonAct" value="' . $DIALOG['JetonAct'] . '">
</div>
';
}
//formulaire d'alerte sur Sujet, Commentaire ou User (Id complété par Javascript)
function Kom1_carteAlerte($IdMaj, $libelleAlerte, $createur = '', $dateCreation = '') {
global $TRANSAC;
echo
'<h2 class="h_alerte">', Beurk_traduit('Alerte', 'Kom1'), '</h2>
<form class="saisieVue" id="', $TRANSAC['Vue']['Form'], '" action="', Kom1_urlReafficheSite(), '" method="post" enctype="application/x-www-form-urlencoded">
', Kom1_formateDivErreur(),
Beurk_fieldset('',
Beurk_baliseInput('text', "refalerte$IdMaj", Beurk_traduit($libelleAlerte, '', $createur, $dateCreation), 'txtreadonly', '', '', 'readonly')),
Kom1_formateValidation('alerte', $IdMaj, Beurk_traduit('votre alerte', 'Kom1'), true, false),
'</form>
';
}
// affiche une div contenant des SelectBox avec les BBcodes gérés, pour insertion dans une textbox
function Kom1_formateDivBBcodes($ActMaj, $IdMaj, $extraActions = '') {
global $CONFIG, $TRANSAC;
$langues = '';
foreach ($CONFIG['Controle']['Langue'] as $IdLangue => $Langue)
$langues .= '<option value="' . $Langue . '">' . $Langue . '</option>
';
return
'<fieldset>
<legend>' . Beurk_traduit('Mise en forme', 'Kom1') . ' :</legend>
<div id="bbcodes">
<select name="BBstyle" tabindex="9000" data-bbcode="' . $ActMaj . '/' . $IdMaj . '/">
<option value=" " selected>' . Beurk_traduit('Style', 'Kom1') . '</option>
<option value="b">' . Beurk_traduit('gras', 'Kom1') . '</option>
<option value="i">' . Beurk_traduit('italique', 'Kom1') . '</option>
<option value="u">' . Beurk_traduit('souligné', 'Kom1') . '</option>
<option value="s">' . Beurk_traduit('barré', 'Kom1') . '</option>
</select>
<select name="BBclas" tabindex="9001" data-bbcode="' . $ActMaj . '/' . $IdMaj . '/clas">
<option value=" " selected>' . Beurk_traduit('Classe', 'Kom1') . '</option>
<option value="Gauche">' . Beurk_traduit('gauche', 'Kom1') . '</option>
<option value="Droite">' . Beurk_traduit('droite', 'Kom1') . '</option>
<option value="Seul">' . Beurk_traduit('seul', 'Kom1') . '</option>
</select>
<select name="BBcolor" tabindex="9002" data-bbcode="' . $ActMaj . '/' . $IdMaj . '/color">
<option value=" " selected>' . Beurk_traduit('Couleur', 'Kom1') . '</option>
<option value="red">' . Beurk_traduit('rouge', 'Kom1') . '</option>
<option value="blue">' . Beurk_traduit('bleu', 'Kom1') . '</option>
<option value="green">' . Beurk_traduit('vert', 'Kom1') . '</option>
<option value="yellow">' . Beurk_traduit('jaune', 'Kom1') . '</option>
<option value="black">' . Beurk_traduit('noir', 'Kom1') . '</option>
<option value="grey">' . Beurk_traduit('gris', 'Kom1') . '</option>
<option value="turquoise">' . Beurk_traduit('turquoise', 'Kom1') . '</option>
<option value="orange">' . Beurk_traduit('orange', 'Kom1') . '</option>
<option value="brown">' . Beurk_traduit('marron', 'Kom1') . '</option>
</select>
<select name="BBlangue" tabindex="9003" data-bbcode="' . $ActMaj . '/' . $IdMaj . '/lang">
<option value=" " selected>' . Beurk_traduit('Langue', 'Kom1') . '</option>
' . $langues .
'</select>
<select name="BBinsere" tabindex="9004" data-bbcode="' . $ActMaj . '/' . $IdMaj . '/">
<option value=" " selected>' . Beurk_traduit('Insérer', 'Kom1') . '</option>
<option value="*">' . Beurk_traduit('élément', 'Kom1') . '</option>
<option value="list*">' . Beurk_traduit('liste *', 'Kom1') . '</option>
<option value="list9">' . Beurk_traduit('liste 9', 'Kom1') . '</option>
<option value="img">' . Beurk_traduit('image', 'Kom1') . '</option>
<option value="url">' . Beurk_traduit('lien', 'Kom1') . '</option>
<option value="mp3">' . Beurk_traduit('mp3', 'Kom1') . '</option>
<option value="code">' . Beurk_traduit('code', 'Kom1') . '</option>
<option value="quote">' . Beurk_traduit('citation', 'Kom1') . '</option>
</select>' . (($extraActions != '') ? '
' . $extraActions : '') . '
</div>
</fieldset>
';
}
// fonction qui génère une image à partir d'une chaine de caractère pour test de Turing
function Kom1_SecImage($chaine) {
global $CONFIG, $DIALOG;
$fontNum = 5; // plus grande police par défaut dans PHP
$longChaine = strlen($chaine);
$largeurCarac = imagefontwidth($fontNum);
$hauteurCarac = imagefontheight($fontNum);
$couleur = $CONFIG['Controle']['Palette']['_site'][ $DIALOG['Style'] ]['erreur'];
// création de l'image avec le fond
$image = imagecreatetruecolor( $largeurCarac * ($longChaine + 2), // largeur
$hauteurCarac * 2); // hauteur
$couleurTexte = imagecolorallocate($image, hexdec(substr($couleur, 0, 2)), hexdec(substr($couleur, 2, 2)), hexdec(substr($couleur, 4, 2)));
$couleur = $CONFIG['Controle']['Palette']['_site'][ $DIALOG['Style'] ]['fond0'];
$couleurFond = imagecolorallocate($image, hexdec(substr($couleur, 0, 2)), hexdec(substr($couleur, 2, 2)), hexdec(substr($couleur, 4, 2)));
imagefilledrectangle($image, 0, 0, 100, 30, $couleurFond);
for ($noLettre = 0; $noLettre < $longChaine; $noLettre++) { // création du texte
imagechar( $image, $fontNum,
($noLettre + 1) * $largeurCarac, // x
($hauteurCarac / 2), // y
substr($chaine, $noLettre, 1), $couleurTexte);
/*imagettftext( $image,
rand(10, 13), // taille
rand(-15, 15), // angle
5 + ($noLettre * ($largeurCarac + 2)) + rand(-2, 2), // x
5 + rand(-4, 5), // y
$color, INSTALL_PATH . '/xxx/Arial.tff', substr($chaine, $noLettre, 1)
); //pas testé */
}
ob_start();
imagepng($image);
$chaineImage = ob_get_clean();
imagedestroy($image);
return '<img class="capChat" src="data:image/png;base64,' . base64_encode($chaineImage) . '" />';
}