Commit 4facddb9 authored by GROSS-AMBLARD David's avatar GROSS-AMBLARD David
Browse files

Reinstalls config.php.example

parent 24fd5ecb
<?php
/**
* Configuration file
*
*/
// Set DEBUG to true to see plenty of error messages
//define("DEBUG",false);
define("DEBUG",true);
// Location of the log file
define("LOGFILENAME","log/log.txt");
// Add more error messages from PHP
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
// Mysql parameters
define("SERVERNAME","localhost");
define("USERNAME","");
define("PASSWORD","");
define("DATABASE","headwork");
// Wirk connector parameters
define("WIRKAPIUSER","headwork_wirk.io");
define("WIRKAPIPASSWORD","");
define("WIRKAPPID","853");
define("WIRKQUALITYID","1386");
define("WIRKPROJECTENDPOINT","https://api.wirk.io/v1_0/AppProject");
define("WIRKTASKLINEENDPOINT","https://api.wirk.io/v1_0/TaskLine");
// Bot parameters
define("NBBOTS",10);
?>
# Cool-In
## Cas d'usages
- Acheter du pain
- Organiser l'anniversaire de mon fils
- Demander les copains qu'ils veut
- Faire les cartes d'invitation
- Acheter les cadeaux
- Récupérer la participation des parents
- Faire la déco
- Faire les courses
- Commander le gâteau
- Ranger
- Charger l'appareil photo
- Charger le camescope
- Envoyer des photos aux parents
- urgent, payer impot
- pour le 5/12, review BDA
- écrire le rapport
- 1 faire le plan
- 1 récupérer le modele
- 2 valider le plan
- rester en forme
- chaque jour
- faire des pompes
- faire des squats
- entretenir la voiture
## Idées
- Proposer Heisenowher
- Mettre un temps par défaut, basé sur historique
- Echelle 5mn, 1/2 journée, journée, si plus il faudra splitter
- proposer un style (tutoiement, ...)
- s'inspirer de la syntaxe MD ou org-mod
- vue jour / semaine / mois / année
- capacité à ingurgiter des todos manuscripts (tesseract?)
- montrer la proposition de calendrier
- vue jour/semaine/mois
- donner le rapport entre estimation du temps et réalité
- indiquer qu'on commence et qu'on fini un truc
- demander si une tâche s'est bien passée (génial, content, pas content)
- proposition visible en ics
- proposer de déléguer ?
- si c'est court, le faire tout de suite
- urgent/important d'abord
- donner des rôles (travail, famille, personnel)
- equilibrer des rôles
- avoir un score de stress cumulé (trouver un modèle de stress)
- proposer des choses, en relation avec des agenda thématiques (et si vous alliez au cinéma voir ...)
- vue "Et maintenant", qui permet de dire "pas maintenant"
- faire un design avec fluidui
- comparer avec Google Next et autres
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -9,4 +9,5 @@
* Directory pages X
* file X.php
* in it, a X function, taking $conn as input
*
\ No newline at end of file
* limited HTML in code
* No direct use of PDO->query, only prepared statements
......@@ -20,13 +20,10 @@ else {
die("Headwork is not properly installed yet. Set a config.php file (use the config.php.example template).");
}
require_once("lib/HWlib.php");
require_once("lib/HTML.php");
require_once("lib/artifacts.php");
require_once("pages/skills/skills.php");
require_once("tasks.php");
require_once("connection.php");
require_once("pages/workflowdesign/workflowdesign.php");
require_once("pages/showCredit/showCredit.php");
require_once("pages/showState/showState.php");
......@@ -43,6 +40,7 @@ require_once("pages/feedback/feedback.php");
require_once("pages/forum/forum.php");
require_once("pages/taskViewer/TaskViewer.php");
// TODO faire une classe avec action($conn,$context), qui va appeler la fonction précise avec les $_GET (tout est sur ce format)
session_start();
......@@ -58,7 +56,7 @@ try { // global exception catcher
$conn = HWdbconnect();
$mode = login($conn);
$mode = (new LoginForm($conn))->login($conn);
$_SESSION['mode']=$mode;
$VIEW = array("MAIN" => "");
......@@ -72,6 +70,13 @@ debug("mode is : $mode");
switch ($mode) {
case "login":
// prototype of the future $mode call system with pageList security test
$pageList=array("login"=>"LoginForm");
if(array_key_exists($mode,$pageList)){
$class=$pageList[$mode];
$obj=new $class($conn);
$obj->render();
}
loginForm($conn);
break;
case "register":
......@@ -127,9 +132,12 @@ switch ($mode) {
break;
case "showCredit":
// prototype of the future $mode call system with pageList security test
$pageList=array("showCredit");
if(in_array($mode,$pageList))
$mode();
$pageList=array("showCredit"=>"Credits");
if(array_key_exists($mode,$pageList)){
$class=$pageList[$mode];
$obj=new $class($conn);
$obj->render();
}
break;
case "maintenance":
maintenance();
......
......@@ -5,7 +5,7 @@
* In Mysql
* create a "headwork" database
* create a user "headworkadmin" with all privileges on headwork db with default password "HEAg2r4a3g2"
* run sql commands in init-db-schema.sql with e.g. mysql -u headworkadmin -p headwork < init-db-schema.sql
* run sql commands in script/init-db-schema.sql with e.g. mysql -u headworkadmin -p headwork < init-db-schema.sql
* Open the headwork home in your browser (typically http://localhost:8888/headwork)
* The demo account is "Demo"/"Demo"
* Click "restart" to restart the workflow
......@@ -36,7 +36,7 @@ sudo apt install libapache2-mod-php7.2
* run sql commands in init-db-schema.sql
```
mysql -u headworkadmin -p headwork
mysql> source init-db-schema.sql;
mysql> source script/init-db-schema.sql;
```
* start apache
```
......
<?php
session_start();
require("HTML.php");
require("HWlib.php");
$VIEW=array("MAIN"=>"");
$user=$_SESSION['id'];
$conn=HWdbconnect();
$page = "";
switch ($_GET['mode']) {
case "feedback":
$page = isnlpFeedback($conn);
break;
case "answers":
default:
$page = isnlpAnswers($conn);
break;
}
if (isset($_SESSION['username'])) {
debug("logged");
$stmt = $conn->prepare("select wallet from UserProfile where id=:id");
$stmt->bindParam(':id', $_SESSION["id"], PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$line = $stmt->fetch();
$var = array("ID" => $_SESSION['username'], "wallet" => $line['wallet']);
} else debug("unlogged");
$VIEW['MAIN'] .= HTMLdiv($page);
require("template-main.php");
/**
* Retrieve all the accepted queries and their correction
* @param PDO $conn a valid PDO database connection
*/
function isnlpAnswers($conn) {
$page = HTMLh1("Bienvenue sur la page du sujet");
// Retrieve all queries
$stmt = $conn->query("SELECT q.idq, q.value as 'query', p.value as 'correction', p.help FROM bdd_query q, bdd_proposal p WHERE p.idq = q.idq AND (oracle_approved OR ((SELECT count(*) FROM bdd_proposal WHERE total_approved = (SELECT MAX(total_approved) FROM bdd_proposal WHERE bdd_proposal.idq = q.idq) AND bdd_proposal.idq = q.idq GROUP BY p.idq) = 1 AND total_approved = (SELECT MAX(total_approved) FROM bdd_proposal WHERE bdd_proposal.idq = q.idq))) group by p.idq, p.idp ORDER BY q.total_score / voters_nb");
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$divLeftContent = HTMLp("<p>On considère le schéma relationnel suivant :<br>MOVIE(<u>id_movie</u>, title, length, release_date, director)<br>ACTOR(<u>id_actor</u>, name, firstname, birthdate, nationality)<br>PLAYED_IN(<u>id_actor#, id_movie#</u>)</p>");
$divLeftContent .= HTMLp("Traduisez ces requêtes en SQL :");
$fullContent = "";
$i = 1;
foreach ($result as $req) {
$btnDiv = HTMLdiv(
HTMLtagblock(
"button",
array(
"class" => "btn btn-dark badge badge-dark collapsed",
"data-toggle" => "collapse",
"data-target" => "#collapsedCorrection".$req["idq"]
),
"Afficher la correction"
)
);
$justification = "";
if (isset($req['help'])) {
$help = json_decode($req['help']);
$justification = HTMLdiv(HTMLtagblock("a", array("href" => $help->link, "target" => "_blank"), "Justification".(strlen($help->page) > 0 ? " (page ".$help->page.")" : "")), array("class" => "text-muted"));
}
$collapsedCorrection = HTMLdiv($req["correction"].$justification, array("class" => "collapse", "id" => "collapsedCorrection".$req["idq"]));
$textDiv = HTMLdiv(HTMLtagblock("strong", array(), $i.". ".$req["query"]).$collapsedCorrection);
$contentLi = HTMLtagblock("li", array("class" => "list-group-item d-flex justify-content-between align-items-center text-left"), $textDiv.$btnDiv);
$fullContent .= $contentLi;
$i++;
}
$contentUl = HTMLtagblock("ul", array("class" => "list-group"), $fullContent);
$downloadBtns = HTMLdiv(HTMLtag("br").HTMLtagblock("a", array("class" => "btn btn-info", "href" => "isnlp/sujet.html", "download" => "sujet.html"), "Download HTML file").HTMLtagblock("a", array("class" => "btn btn-info", "href" => "isnlp/sujet.tex", "download" => "sujet.tex"), "Download LaTeX file")
);
$div = HTMLdiv($divLeftContent.$contentUl.$downloadBtns, array("class" => "text-left"));
$page .= HTMLtagblock("h3", array(), $div);
generateIsnlpHtml($contentUl);
generateIsnlpLatex($result);
return $page;
}
/**
* Retrieve all the feedback of the queries proposed by the user
* @param PDO $conn a valid PDO database connection
*/
function isnlpFeedback($conn) {
$user = $_SESSION['id'];
$page = HTMLh1("Feedback de vos requêtes proposées");
$page .= "<table class='table table-bordered'>";
$page .= "<thead class='thead-dark'><tr><th scope='col'>Requête proposée</th><th>Remarques</th></tr></thead>";
$page .= "<tbody>";
// Retrieve all feedback and the relevant queries
$stmt = $conn->prepare("SELECT q.value, f.idf, f.feedback FROM bdd_query q, bdd_feedback f WHERE q.idq = f.idtask AND q.iduser = :user ORDER BY q.value ASC");
$stmt->execute(array("user" => $user));
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$lastQuery = ""; // The previous query (used to compare)
$nbRows = 1; // The number of rows the query must take in the table (rowspan attribute)
$tempFeedbackArray = []; // Temporary array containing feedbacks within td tags
$modalArray = []; // The array of modals, added at the end for a cleaner HTML
// Iterating through results
foreach ($results as $row) {
$fbText = $row['feedback'];
$query = $row['value'];
if ($query == $lastQuery) {
$nbRows++;
} else { // If a new query is detected, we add all the feedback to the table, without repeating the involved query
$i = 0;
foreach ($tempFeedbackArray as $rowElements) {
$page .= "<tr>";
if ($i == 0) {
$page .= "<td rowspan='".$nbRows."'>".$lastQuery."</td>";
}
$page .= $rowElements."</tr>";
$i++;
}
$nbRows = 1;
$lastQuery = $query;
$tempFeedbackArray = [];
}
// Creating a modal if the feedback is too long
$displayedText = "";
if (strlen($fbText) > 72) {
$displayedText = HTMLtagblock("a", array(
"href" => "#",
"style" => "color: black;",
"data-toggle" => "modal",
"data-target" => "#moreInfoIsnlpFeedback".$row['idf']
), substr($fbText, 0, 60)."… (voir plus)");
array_push($modalArray, generateIsnlpFeedbackModal($row));
} else {
$displayedText = $fbText;
}
array_push($tempFeedbackArray, "<td>".$displayedText."</td>");
}
// Adding the feedback of the latest query to the table
$i = 0;
foreach ($tempFeedbackArray as $rowElements) {
$page .= "<tr>";
if ($i == 0) {
$page .= "<td rowspan='".$nbRows."'>".$lastQuery."</td>";
}
$page .= $rowElements."</tr>";
$i++;
}
$page .= "</tbody></table>";
// Adding generated modals to the page
foreach ($modalArray as $modal) {
$page .= $modal;
}
return $page;
}
/**
* Generate a downloadable HTML file
* @param string $contentUl
*/
function generateIsnlpHtml($contentUl) {
$file = "isnlp/sujet.html";
$writer = fopen($file, "w");
$data = "<!DOCTYPE html>
<html>
<head>
<title>Sujet généré</title>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css'>
<link rel='stylesheet' href='https://drvic10k.github.io/bootstrap-sortable/Contents/bootstrap-sortable.css'>
</head>
<body>
<div class='container'>
<div class='row'>
<div class='col-12'>
<h3>Bienvenue sur la page du sujet généré</h3>
<p>On considère le schéma relationnel suivant :<br>
MOVIE(<u>id_movie</u>, title, length, release_date, director)<br>
ACTOR(<u>id_actor</u>, name, firstname, birthdate, nationality)<br>
PLAYED_IN(<u>id_actor#, id_movie#</u>)</p>
<p>Traduisez ces requêtes en SQL :</p>
$contentUl
</div>
</div>
</div>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
<script src='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js'></script>
</body>
</html>
";
fwrite($writer, $data);
fclose($writer);
}
/**
* Generate a downloadable uncompiled LaTeX file
*/
function generateIsnlpLatex($queries) {
$file = "isnlp/sujet.tex";
$writer = fopen($file, "w");
$data = "\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\\title{Sujet de bases de données}
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\begin{document}
\maketitle
\section{Requêtes SQL}\\noindent
On considère le schéma relationnel suivant :\\newline
MOVIE(\underline{id\_movie}, title, length, release\_date, director)\\newline
ACTOR(\underline{id\_actor}, name, firstname, birthdate, nationality)\\newline
PLAYED\_IN(\underline{id\_actor\#, id\_movie\#})\\newline\\newline
Traduisez ces requêtes en SQL :
\begin{enumerate}";
foreach ($queries as $row) {
$data .= "
\item ".replaceCharactersLatex($row['query'])."
\begin{verbatim}
".arrangeSqlLatex($row['correction'])."
\\end{verbatim}"
;
}
$data .= "
\\end{enumerate}
\\end{document}";
fwrite($writer, $data);
fclose($writer);
}
/**
* Replace every special character by its latex equivalent
* @param string $string the string to compute
*/
function replaceCharactersLatex($string) {
$toReplace = array('\\', '%', '$', '{', '_', '¶', '‡', '|', '>', '–', '™', '¡', '£', '#', '&', '}', '§', '†', '<', '—', '®', '¿', 'ⓐ', '©');
$replacedBy = array('\\textbackslah', '\\%', '\\$', '\\{', '\_', '\\P', '\\ddag', '\\textbar', '\\textgreater', '\\textendash', '\\textrademark', '\\textclamdown', '\\pounds', '\\#', '\\&', '\\}', '\\S', '\\dag', '\\textless', '\\textemdash', '\\textregistered', '\\textquestiondown', '\\textcircled{a}', '\\copyright');
return str_replace($toReplace, $replacedBy, $string);
}
function arrangeSqlLatex($string) {
$tabs = 0;
$newLineWords = array("FROM", "WHERE", "GROUP", "HAVING", "ORDER", "LIMIT", "UNION", "AND");
$incTab = array("(");
$decTab = array(")");
$toReturn = "";
foreach(explode(" ", $string) as $word) {
$i = 0; // Number of times we need to indent
while ($i < $tabs) {
$toReturn .= "\t";
}
if (in_array(strtoupper($word), $newLineWords)) {
$toReturn .= "\n";
} else if (in_array($word, $incTab)) {
$tabs++;
} else if (in_array($word, $decTab)) {
$tabs--;
}
$toReturn .= $word." ";
}
return $toReturn;
}
function generateIsnlpFeedbackModal($queryRow) {
return '<div class="modal fade" id="moreInfoIsnlpFeedback'.$queryRow['idf'].'" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5>Une remarque par rapport à la requête que vous avez proposé</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body text-left">
<p>'.$queryRow['feedback'].'</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>';
}
?>
\ No newline at end of file
<?php
/*
* An abstract class to model any action in the website. To use, override the render method.
*/
abstract class Action {
protected $conn;
function __construct($conn){
$this->conn=$conn;
}
abstract function render();
}
?>
<?php
/**
* HW library
*
*/
require_once("config.php");
/**
* If global constant DEBUG is true, echoes the parameter string. In any case, log the message.
* @param String The debug message to print/log.
*
*/
function debug($msg){
// get the calling function
$ex = new Exception();
$trace= $ex->getTrace();
$calling="main";
if (array_key_exists(1, $trace))
if(array_key_exists('function',$trace[1]))
$calling = $trace[1]['function'];
$msg=$calling.":".$msg;
$msgHTML=htmlentities($msg);
// conditional web page output
if(DEBUG){
// echo "<p><pre>DEBUG: $msg</pre></p>";
echo "<script type='text/javascript'>";
echo " console.log(\"$msgHTML\");";
echo "</script>";
}
// logfile output
$handle = fopen(LOGFILENAME, "a+") or die('Cannot open log file '.LOGFILENAME);
fwrite($handle, date("r")." $msg\n");
fflush($handle);
}
/*
* Convert a crowdy line into a crowd sql artifact
* Crowdy language:
* ask 10 "What is the height of Sandra Bullock ?"
* take majority
*
* CROWDY := ASK | TAKE
* ASK := ask INT STRING
* TAKE := take AGGREGATE
* AGGREGATE := majority
*
*/
function crowdy2craft($line){
$token=strtok($line,' ');
switch ($token){
case "ask":
$res=readASK($line);
break;
default:$res="syntax error";
break;
}
}
function readASK($line,$source,$sink,$max){
$next=$max+1;
$token=strtok($line,' ');
if($token!="ask")
return "first token: ask awaited";
$count=strtok(' ');
if (!is_numeric($count))
return "requires a population";
$count=intval($count);
$question=strtok('\"');
$artifact=array(
$source=>array(
$next=>array(
"guard"=>"select true from dual",
"actions"=>[
"insert into task(body) values ('$question')",
"insert into profile (select id,'any' from task)"]),
),
$next=>array(
$sink=>array(
"guard"=>"select count(*)>=$count from answer",
"actions"=>array("delete from task")
)
)
);
return array($artifact,$next+1);
}
function HWdbconnect()
{
// database connection
$conn = new PDO("mysql:host=".SERVERNAME.";dbname=".DATABASE."; charset=utf8", USERNAME, PASSWORD);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
debug("Connected successfully");
return $conn;
}
/*
* Given $conn, a valid PDO connection, returns the distinct list of projects from the set of artifact classes
*/
function HWlistProjects($conn){
$projects=array();
$stmt = $conn->query("select distinct project from ArtifactClass");
while($project=@$stmt->fetch()['project'])
array_push($projects,$project);
return $projects;
}
?>
<?php
require_once("wirk.php");
require_once("lib/wirk.php");