Commit 373590a2 authored by GROSS-AMBLARD David's avatar GROSS-AMBLARD David
Browse files

Reorganizes the project structure with /lib and /templates directory.

parent e134e079
......@@ -2,4 +2,4 @@ log/log.txt
projects/spipoll/*
.*
config.php
HWlib.php
\ No newline at end of file
lib/HWlib.php
\ No newline at end of file
<?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;
}
?>
......@@ -56,7 +56,7 @@
*/
// TODO here convert into drawArtifact function
require_once("artifacts.php");
require_once("lib/artifacts.php");
//Fonction récursive pour convertir un tableau d'artifact en ligne sugarfree
function recursiveConvertSugarFree(array $data, array &$convertedData = []){
......
......@@ -21,15 +21,15 @@ else {
}
require("HWlib.php");
require("HTML.php");
require("lib/HWlib.php");
require("lib/HTML.php");
require("lib/artifacts.php");
require("profile.php");
require("skills.php");
require("tasks.php");
require("actions.php");
require("connection.php");
require("show-pages.php");
require("artifacts.php");
require("show-artifact.php");
require("drawArtifact.php");
require("workflowdesign.php");
......@@ -180,7 +180,7 @@ switch ($mode) {
if (isset($_SESSION['username']))
@$var = array("ID" => $_SESSION['username']);
require("template-main.php");
require("templates/template-main.php");
}
catch (Exception $e){ // global exception handler
......
DELETE from CURRENTARTIFACT where NAME = (select TABLENAME from ARTIFACTCLASS where project = 'SPIPOLL');
DELETE from ARTIFACT where CLASSID = (select id from ARTIFACTCLASS where project = 'SPIPOLL');
DELETE from ARTIFACTCLASS where project = 'SPIPOLL';
DELETE from profile;
DELETE from task;
DELETE from answer;
DELETE from result;
ALTER TABLE ARTIFACT AUTO_INCREMENT = 1;
ALTER TABLE task AUTO_INCREMENT = 2;
DELETE FROM chat_post;
DELETE FROM chat_topic;
ALTER TABLE chat_post AUTO_INCREMENT = 1;
ALTER TABLE chat_topic AUTO_INCREMENT = 1;
drop table if exists SpipollArtifact;
-- create table if not exists SpipollArtifact (image_path varchar(1000),id int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB DEFAULT CHARSET=utf8;
create table if not exists SpipollArtifact(
id int primary key auto_increment,
idartifact int default null,
file varchar(100) default null,
niveau int default null,
ordre varchar(255) default null,
famille varchar(255) default null,
genre varchar(255) default null,
espece varchar(255) default null,
label varchar(255) default null
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- insert into SpipollArtifact(image_path) values ('files/spipoll/image1.jpg');
insert into ARTIFACTCLASS(id,description,definition,tablename,project) values (5000,'The Spipoll Artifact','spipollIRhw.sca', 'SpipollArtifact', 'SPIPOLL');
insert into SpipollArtifact (idartifact, file, niveau, ordre, famille, genre, espece, label) values (5000,'files/spipoll/image1.jpg', 1, null, null, null, null, null);
insert into ARTIFACT(OWNERID,CLASSID,STATE,NODE,ATTRIBUTES) values ('1','5000','running',1,1);
-- insert into CURRENTARTIFACT(ID,NAME,USER) values (1,'IsnlpArtifact', 1);
-- insert into CURRENTARTIFACT(ID,NAME,USER) values (1,'IsnlpArtifact', 2);
-- insert into CURRENTARTIFACT(ID,NAME,USER) values (1,'IsnlpArtifact', 3);
-- insert into CURRENTARTIFACT(ID,NAME,USER) values (1,'IsnlpArtifact', 4);
Markdown is supported
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