Commit 396ed1df authored by Mathieu Loiseau's avatar Mathieu Loiseau
Browse files

slightly improved admin

parent 06a311f7
......@@ -14,8 +14,21 @@ Installation
* Download from GitHub and unzip
* Create a "./enregistrements" folder (make sure your Apache server has writing rights in this directory)
* Make sure apache also has writing rights in "./profil" directory
* Edit ./sys/config.sample.php, enter identification to your MySQL or MariaDB server and save the file as ./sys/config.php
* If you want the recordings stored in mp3 format on the server, libavtools >=9 must be installed and the $conversion variable initialization adjusted in ./sys/config
* If you want some cards in various languages you can uncomment the "include_once('provided_cards.php');" at the end of initializeDB.php
* If you want some cards in various languages you can uncomment the "include_once('import.php');" at the end of initializeDB.php
* Run initializeDB.php
* You're good to go
./adminCards.php provides very unsafe administration and should not be kept on the server unless you are about to use it. It allows 2 types of actions :
* admin (GET variable admin is set e.g. http://localhost/adminCards.php?admin=true) : see all the cards, to decide which ones should not be submitted to players (default case as well, if no get variable is set).
* export (GET variable export is set e.g. http://localhost/adminCards.php?export=true) : generate code that can be used to import the said card in another system. NB : the authorship in the next instance will be lost and the cards associated to the admin account
* user generated cards only (GET variable ugc is set e.g. http://localhost/adminCards.php?ugc=true) : only export (or admin, or both) the cards that were created by users.
import can automatically performed on install.
It imports the cards we provided and cards you might have exported (see administration). The parameter in the store method in all import script checks whether two cards can concern the same words. It is set to true by default, so that the system checks whether the word exists and refuses same word cards. If you want those cards, you should find occurences of “store(true)” and replace them by “store(false)” before running the import script for the 1st time. (“true” might be a word in your cards)
......@@ -12,22 +12,56 @@ require('./languages/language.php');
$user = user::getInstance();
$userlogged = $user->logged_in();
if ( !$userlogged ){
if ( !$userlogged || $user->username != 'admin'){
header('Location: index.php');
$admin = (isset($_GET["admin"]) ||
(!isset($_GET["export"]) && !isset($_GET["admin"])) );
$export = isset($_GET["export"]);
$ugc = isset($_GET["UGC"]);
$title = 'Game of Words / Administration';
echo "<script type='text/javascript' src='./controllersJS/menu_lang.js'> </script>";
echo "<h1>".$lang['admin']."</h1>";
$h1 = "";
echo "<h1>".$lang['admin']."</h1>";
$cardFactory = new ItemFactory($user->id,$user->langGame);
$card_ids = $cardFactory->get_card_ids(ItemFactory::ALL_CARDS);
$card_ids = $cardFactory->get_card_ids(ItemFactory::ALL_UG_CARDS);
$card_ids = $cardFactory->get_card_ids(ItemFactory::ALL_CARDS);
$export_txt = "&lt;?php echo \"&lt;h2&gt;User created cards&lt;/h2&gt;\";\n";
$export_txt .= "\$nb=0;\ntry{\n";
foreach ($card_ids as $card_id){
$card = new Card($card_id);
echo $card;
$card = new Card($card_id);
echo $card;
$export_txt .= $card;
$export_txt .= "\n}catch(Exception \$e){echo \$e;}";
$export_txt .= "\n\necho \"&lt;p&gt;&lt;strong&gt;\$nb&lt;/strong&gt; user cards imported :D&lt;/p&gt;\";";
$export_txt .= "?&gt;";
echo "<h1>".$lang['export']."</h1>";
echo "<p>".$lang['export_disclaimer']."</p>";
$fich = fopen("./enregistrements/exported_cards.php","w");
fwrite($fich, str_replace(array("&lt;", "&gt;"), array("<",">"), $export_txt));
echo "<pre style='clear:both'>$export_txt</pre>";
<?php header('Content-Type: text/html; charset=UTF-8');
<title>Importation de cartes créées par des contributeurs d'Innovalangues ou des collègues</title>
error_reporting(E_ALL);//error_reporting(0); désactiver
ini_set('display_errors', '1');
echo "No user cards to import (add them to './exported_cards.php', if you have some).";
......@@ -207,5 +207,5 @@ foreach($sql_query as $sql){
echo $i++."<br />";
$db->query($sql) or die('error in query: '.$sql);
\ No newline at end of file
......@@ -260,4 +260,6 @@ $lang["AJAX_noquery"] = "No query, actually…";
//Administration cartes
$lang['admin'] = "Administration: Press cross to delete card";
$lang['export'] = "Export code to be run when you want to import those cards";
$lang['export_disclaimer'] = "The following content will be written in “./enregistrements/exported_cards.php”. It will be executed when you run “./import.php”. It should not break anything, but it might, so be careful.";
......@@ -254,3 +254,5 @@ $lang["AJAX_noquery"] = "Pas de requête, en fait…";
//Administration cartes
$lang['admin'] = 'Administration&nbsp;: Cliquer sur la croix pour supprimer la carte';
$lang['export'] = "Export de code, à exécuter pour réimporter les cartes";
$lang['export_disclaimer'] = "Le contenu ci-dessous sera écrit dans «&nbsp;./enregistrements/exported_cards.php&nbsp;». Il sera exécuté quand vous chargerez «&nbsp;./import.php&nbsp;». Ça ne devrait rien casser, mais on ne sait jamais, faites attention.";
......@@ -148,8 +148,8 @@ class Card
public function store($prompt=false){
$this->db->query("SELECT `idCarte` FROM `cartes` WHERE `mot`='".$this->guessWord."';");
$nb = $this->db->affected_rows ;
$this->db->query("SELECT `idCarte` FROM `cartes` WHERE `mot`='".$this->guessWord."' AND `langue`='".$this->lang."';");
$nb = $this->db->num_rows() ;
if($nb > 0){
//TODO : better compare with actual objects
//and check the forbidden words and all…
......@@ -6,6 +6,7 @@ class ItemFactory //a quick and dirty class…
{ //…to encapsulate some "complicated" frequent queries
const ANY = 1;
const ALL_CARDS = 6;
const ALL_UG_CARDS = 7;//User generated means not created by admin user…
const CARD_NOT_ME = 2;
......@@ -108,10 +109,11 @@ class ItemFactory //a quick and dirty class…
case self::ALL_CARDS:
//partir sur cette piste ce serait peut être mieux : SELECT `cartes`.*, GROUP_CONCAT(`mots_interdits`.`mot` SEPARATOR '|') as `interdits` FROM `cartes`,`mots_interdits` WHERE `cartes`.`idCarte`=`mots_interdits`.`idCarte` GROUP BY `mots_interdits`.`idCarte` ORDER BY `cartes`.`langue`, `cartes`.`idCarte`
//mais c'est un peu fatiguant…
$this->query = "SELECT `idCarte` as `zeId` FROM `cartes` WHERE `cartes`.`idEraser` IS NULL ORDER BY `langue`, `idCarte` $forOne";//le forOne servira pas, pour la cohérence
case self::ALL_UG_CARDS:
$this->query = "SELECT `idCarte` as `zeId` FROM `cartes` WHERE `cartes`.`idDruide`!='1' AND `cartes`.`idEraser` IS NULL ORDER BY `langue`, `idCarte` $forOne";//le forOne servira pas, pour la cohérence
$res = false;
This diff is collapsed.
<?php /* Global $card sent by Card class (models/card.class.php) → $res used then in Card class*/
$res = "\n\$tempObj = new Card('".$card->get_lang()."', NULL, \"".$card->get_level().'", "'.$card->get_cat().'", "1", "'.$card->get_word().'",'."\n\t".' array("'.implode('","', $card->get_forbidden_words()).'"),'."\n\t".' array("'.implode('","', $card->get_themes()).'"));'."\n";
$res .= "\t\$tmpObj->store(true);\$nb++;";
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment