addGlobalVar("page_titre", "Forum :: Créer un sujet"); $tmpl->addVar("forum_users-edit-thread","titre","Edition d'un thread"); $forum = $sql->query("SELECT * FROM forum_categories WHERE id = '".$sql->quote($_GET["id"])."'"); function remove_js($contents) { while(true) { $begPos = strpos($contents,"",$begPos+strlen("")); $contents = $tmp; if ($loopcontrol++>100) break; //loop infinity control continue; //search again } return $contents; } if(empty($forum)) { $isPrivate = false; $forumID = null; } else { $isPrivate = $forum[0]['private'] == '1' ? true : false; $forumID = $forum[0]['id']; } if(!isset($_SESSION["loginid"])) { $tmpl->readTemplatesFromInput("erreur.tmpl"); $tmpl->addVar("erreur", 'contenu', utf8_decode('Vous devez être connecté pour accéder à cette page !')); $tmpl->addVar("erreur", 'url_retour','/forum/'); $tmpl->addVar("erreur", 'texte_retour', "Retour aux Forums"); $tmpl->displayParsedTemplate('erreur'); exit; } $modo = 0; $droits_ok = 1; $droits = $aaa->get_droits($_SESSION["loginid"]); if(in_array('newser',$droits) || in_array('administrateur',$droits) || in_array('moderateur',$droits)) { $modo = 1; } if($droits_ok) { $tmpl->readTemplatesFromInput("forum_users-new-thread.tmpl"); //$tmpl->addVar("form","texte",str_replace("\r\n","",nl2br($thread[0]["texte"]))); $tmpl->addVar("forum_users-new-thread","url_post",$_GET["id"]."-".$_GET["page"]."-".urlcompliant($thread[0]["titre"]).".html"); if($modo) { $liste_forums = $sql->query("SELECT * FROM forum_categories WHERE private >= '0' AND cache = '0'"); } else { $liste_forums = $sql->query("SELECT * FROM forum_categories WHERE private = '0' AND cache = '0'"); } $forum_enum = Array( Array( "label" => "Choisissez..." , "value" => "" ) , //Array( "label" => "INNEXISTS..." , "value" => "17894" ) , C'était pour tester si la vérif fonctionnait => elle fonctionne ! ); foreach($liste_forums as $liste_forum) { array_push($forum_enum, Array("label" => $liste_forum['nom'], "value" => $liste_forum['id'])); } $defaultForum = $forumID; if(isset($_POST['forum']) && !empty($_POST['forum'])) { $forumPosted = $_POST['forum']; foreach($forum_enum as $fEnum) { if($fEnum['value'] == $forumPosted) { $defaultForum = $forumPosted; break; } } } $elementsDefinition = array( 'titre' => array( 'type' => 'String', 'attributes' => array( 'id' => 'titre', 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Titre', 'title' => 'Titre', 'description' => 'Titre du sujet', 'default' => '', 'maxlength' => '60', 'minlength' => '5' ), ), 'forum' => array( 'type' => 'Enum', 'attributes' => array( 'id' => 'forum', 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Forum de destination', 'title' => 'Forum de destination', 'description' => 'Forum de destination', 'default' => $defaultForum, 'values' => $forum_enum ), ), ); $form =& patForms::createForm($elementsDefinition, array( 'name' => 'myForm' , 'action' => '' )); $renderer =& patForms::createRenderer('patTemplate'); $renderer->setTemplate($tmpl); $form->setRenderer($renderer); $form->setAutoValidate('save'); $args = array( 'tmplName' => 'form', 'errorTemplateContainer' => 'errors', 'errorTemplate' => 'error' ); $tmpl = &$form->renderForm($args); $tmpl->addVar("form","texte",remove_js($_POST["elm1"])); if($form->isSubmitted() && $form->validateForm()) { // Vérif texte du post non vite if($_POST["elm1"] == "") { $tmpl->setAttribute( "errors", "visibility", "visible" ); $tmpl->setAttribute( "error", "visibility", "visibile" ); $tmpl->setAttribute( "error1", "visibility", "hidden" ); $tmpl->addvar("error","field_label","Contenu"); $tmpl->addvar("error","error_message", utf8_decode("Vous devez spécifier un contenu pour votre sujet.")); } else if($_POST['titre'] == "" || ctype_space($_POST['titre'])) { $tmpl->setAttribute( "errors", "visibility", "visible" ); $tmpl->setAttribute( "error", "visibility", "hidden" ); $tmpl->setAttribute( "error1", "visibility", "visible" ); $tmpl->addvar("error1","error_desc_field","Titre"); $tmpl->addvar("error1","error_desc", utf8_decode("Vous devez spécifier un titre pour votre sujet.")); } else { if(!isset($_POST['forum']) || empty($_POST['forum']) || ctype_space($_POST['forum'])) { $tmpl->setAttribute( "errors", "visibility", "visible" ); $tmpl->setAttribute( "error", "visibility", "hidden" ); $tmpl->setAttribute( "error1", "visibility", "visible" ); $tmpl->addvar("error1","error_desc_field","Forum de destination"); $tmpl->addvar("error1","error_desc", utf8_decode("Vous devez sélectionner un forum de destination pour votre sujet.")); } else { $forumToPost = htmlspecialchars($_POST['forum']); $checkForumToPost = $sql->query("SELECT * FROM forum_categories WHERE id = '".$forumToPost."'"); if(count($checkForumToPost) > 0) { $result = $sql->query("SELECT * FROM forum_threads WHERE (ip = '".$_SERVER["REMOTE_ADDR"]."' OR pseudo = '".$sql->quote($_SESSION["loginid"])."') AND date > UNIX_TIMESTAMP()-60"); if (count($result) == 0) { $new_read_by[$_SESSION["loginid"]] = "1"; $new_read_by = serialize($new_read_by); //Ajout dans la BDD $dateSave = time(); $sql->query("INSERT INTO forum_threads (cat_id,login_id,pseudo,date,titre,texte,ip,last_post_date,last_post_read) VALUES ('".$checkForumToPost[0]["id"]."','".$_SESSION["loginid"]."','".$aaa->IdToPseudo($_SESSION["loginid"])."','".$dateSave."','".$sql->quote($_POST["titre"])."','".$sql->quote(remove_js($_POST["elm1"]))."','".$_SERVER["REMOTE_ADDR"]."','".$dateSave."','".$new_read_by."');"); $last_id = $sql->query("SELECT * FROM forum_threads WHERE date = '".$dateSave."'"); Header("Location: /forum/sujet-".$last_id[0]['id']."-0-".urlcompliant($_POST['titre']).".html"); } else { $tmpl->setAttribute( "errors", "visibility", "visible" ); $tmpl->setAttribute( "error", "visibility", "hidden" ); $tmpl->setAttribute( "error1", "visibility", "visible" ); $tmpl->addvar("error1","error_desc_field","Anti-flood"); $tmpl->addvar("error1","error_desc","Patientez 60 secondes entre chaque message."); } } else { $tmpl->setAttribute( "errors", "visibility", "visible" ); $tmpl->setAttribute( "error", "visibility", "hidden" ); $tmpl->setAttribute( "error1", "visibility", "visible" ); $tmpl->addvar("error1","error_desc_field","Forum de destination"); $tmpl->addvar("error1","error_desc", utf8_decode("Vous devez sélectionner un forum de destination existant pour votre sujet.")); } } } } $tmpl->displayParsedTemplate("forum_users-new-thread"); } else { $tmpl->readTemplatesFromInput("erreur.tmpl"); $tmpl->addVar("erreur", 'contenu', utf8_decode('Vous n\'avez pas les droits pour accéder à cette page')); $tmpl->addVar("erreur", 'url_retour','/forum/'); $tmpl->addVar("erreur", 'texte_retour', "retour" ); $tmpl->displayParsedTemplate('erreur'); exit; } ?>