VERSION = $version;
}
public function getTodo($pid, $stmt, $req, $id) {
$msg='';$pgm='';$fonc='';$this->pid=$pid;$this->stmt=$stmt;
$pgm=basename(__FILE__, '.php');
$fonc='.getIDTodo() ';$this->fonc=$fonc;
$this->pgm=$pgm;
$msg=' -deb getTodo('.$id.') req: '. $req;$this->msg=$msg;
$ok='ko';$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
//$msg=' -Req postdta:'. $req;$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
//Recup des donnees dans mysql - - - - - - - - - - - - - - - - -
$sql = 'SELECT * FROM todo ' ;
$sql .= " Where titre ='" . $id . "'";
if(strlen($req)>0)$sql=$req;//on surcharge avec la req recu du POST
if($id === 'value')$this->bolColumn=false;//pas de header si on veut recuperer que la valeur
$msg=' -Req:'. $sql;//$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
$bolok= $this->execConn($sql);
$bolok= $this->snd_response($this->arRows);
}
function getAllTodo($pid, $stmt, $req) {
$msg='';$pgm='';$fonc='';$this->pid=$pid;$this->stmt=$stmt;
$pgm=basename(__FILE__, '.php');$this->pgm=$pgm;
$fonc='.getAllTodo() ';$this->fonc=$fonc;
$msg=' -deb getAllTodo(all): req recue:' .$req;$this->msg=$msg;
$ok='ko';$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
//$msg=' -Req postdta:'. $req;$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
//Recup des donnees dans mysql - - - - - - - - - - - - - - - - -
$sql = 'SELECT * FROM todo' ;
if(strlen($req)>0)$sql=$req;
$msg=' -Req:'. $sql;//$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
$bolok= $this->execConn($sql);
$bolok= $this->snd_response($this->arRows);
}//fin getAllTodo()
function saveAllPages($pid, $stmt, $req) {
$msg='';$pgm='';$fonc='';$this->pid=$pid;$this->stmt=$stmt;
$pgm=basename(__FILE__, '.php');$this->pgm=$pgm;
$fonc='.saveAllPages() ';$this->fonc=$fonc;
$msg=' -deb saveAllPages(all): req recue:' .$req;$this->msg=$msg;
$ok='ko';$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
//Update des donnees dans mysql - - - - - - - - - - - - - - - - -
$sql = '';
if(strlen($req)>0){
$sql=$req;
$msg=' -Req:'. $sql;//$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
$bolok= $this->execConn($sql);
$bolok= $this->snd_response($this->arRows);
}
}//fin saveAllPages()
function putAllTodo($pid, $stmt, $req) {
$msg='';$pgm='';$fonc='';$this->pid=$pid;$this->stmt=$stmt;
$pgm=basename(__FILE__, '.php');$this->pgm=$pgm;
$fonc='.putAllTodo() ';$this->fonc=$fonc;
$msg=' -deb putAllTodo(all): req recue:' .$req;$this->msg=$msg;
$ok='ko';$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
//Update des donnees dans mysql - - - - - - - - - - - - - - - - -
$sql = '';
if(strlen($req)>0){
$sql=$req;
$msg=' -Req:'. $sql;//$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
$bolok= $this->execConn($sql);
$bolok= $this->snd_response($this->arRows);
}
}//fin putAllTodo()
function putTodo($pid, $stmt, $req, $id) {
//
$msg='';$pgm='';$fonc='';$this->pid=$pid;$this->stmt=$stmt;
$pgm=basename(__FILE__, '.php');$this->pgm=$pgm;
$fonc='.putAllTodo() ';$this->fonc=$fonc;
$msg=' -deb putAllTodo(all): req recue:' .$req;$this->msg=$msg;
$ok='ko';$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
//Update des donnees dans mysql - - - - - - - - - - - - - - - - -
$sql = '';
if(strlen($req)>0){
$sql=$req;
$msg=' -Req:'. $sql;//$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
$bolok= $this->execConn($sql);
$bolok= $this->snd_response($this->arRows);
}
}//fin putTodo()
public function execConn($sql){
$msg="";
$pgm=basename(__FILE__, '.php');
$fonc='.execConn() ';
$this->msg="";
$this->pgm=$pgm;
$this->fonc=$fonc;
$stmt=$this->stmt;// {select, update, delete, ...}
$conn = $this->open_connexion();
$bolok= $this->log_connexion($conn);//log connexion OK (ou) KO
$arrawsData=array();//tableau d'objet d'array des values
if (strpos($stmt, 'select') !== false){
$bolok=$this->execMysqlReqSelect($conn, $sql);// exec requete si {Select}
}
if (strpos($stmt, 'update') !== false || strpos($stmt, 'save') !== false ){
$bolok=$this->execMysqlReqCMIS($conn, $sql);// exec requete si {insert,delete,update,create,drop}
}
$msg=' -connexion close : ' . $this->msgret;
$conn->close();
$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
/*
$bolok= $this->snd_response($stmt);
$prt = print_r($this->arRows, true);
$msg=' -Prt:'. $prt;$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
$strprt = "";
foreach ($this->arRows as $rowarr) {
foreach ($rowarr as $key => $value) {
$strprt .= "k:=" . $key . " -v:=" . $value .PHP_EOL ;
}
}
$msg=' -strPrt:'. $strprt;$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
*/
return true;
}
public function open_connexion() {
$servername = "localhost";
$username = "obhc6145_FR028923";
$password = "qVd8-faxQ-UU2?";
$dbname = "obhc6145_TODO";
return mysqli_connect($servername, $username, $password, $dbname);
}//fin open_connexion()
public function log_connexion($conn) {
$msg="";$pgm=$this->pgm;$fonc=$this->fonc;
$bolaff=false;
if (!$conn) {
echo 'Echec de la connexion : ' . mysqli_connect_error();
echo PHP_EOL;
echo ' -DOCUMENT_ROOT: ' . $DOCUMENT_ROOT;
echo PHP_EOL;
echo ' -servername: ' . $servername . ' -username:' . $username . ' -password: ' . $password;
echo PHP_EOL;
$bolaff=true;
$msg=' -connexion KO:' . mysqli_connect_error() ;$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
}else{
if ($bolaff){
echo ' connexion OK';
echo PHP_EOL;
}
$msg=' -connexion OK';$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
}
return true;
}//fin log_connexion()
// execMysqlReqCMIS ===================================================
public function execMysqlReqCMIS($conn, $sql) {
$msg="";$pgm=$this->pgm;$fonc="execMysqlU";$this->fonc=$fonc;
$result = mysqli_query($conn, $sql);
/*
En cas d'{insert,drop,create,delete}, mysqli_info() returns un empty string ce qui peut preter a confusion,
tandis que mysqli_affected_rows() returns 1 si (delete, insert) ou 0 si (create, drop).
*/
$this->msgret=$conn->info;
if(strlen($this->msgret)<1){
$b = explode(' ', $sql);//split sur le blanc (insert,delete,update, create, drop)
$this->msgret="Affected rows (" . $b[0] . "): ". mysqli_affected_rows($conn);
}
return true;
}
// execMysqlReqSelect ===================================================
public function execMysqlReqSelect($conn, $sql) {
$msg="";$pgm=$this->pgm;$fonc=".execMysqlS ";$this->fonc=$fonc;
$msg=' -deb execMysqlReqSel: req recue:' .$sql;$this->msg=$msg;
$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
// recup result dans this.arRows array d'objets
$result = mysqli_query($conn, $sql);
//ajout pour debug
$nread=mysqli_num_rows ( $result );
$msg=' .nb lus:' .$nread;$this->msg=$msg;
$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
$v='';$nbr=0;
// Liste le nom,type,.. de la table et ensuite, le nom du champ
/*
for ($i = 0; $i < mysqli_num_fields($result); ++$i) {
// $table = mysqli_field_table($result, $i); // nom de la table
// $field = mysqli_field_name($result, $i); // nom du champ
// totalite des infos des colonnes
$table_info = mysqli_fetch_field_direct($result, $i);
$lenght = $table_info->length;
$field = $table_info->name; // nom du champ
$table =$table_info->table; // todo
$type = $table_info->type; // Text,integer,
$flag = $table_info->flags;//
if ($i<1)$v.=$field;
//else $v.='xxx'.$table . '.' . $field;
else $v.='xxx' . $field;
//$msg=$v;$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
}
*/
$msg=' .recupInfos: nom des colones!';$this->msg=$msg;
$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
$info = $result->fetch_fields();
$i=0;
foreach ($info as $table_info) {
$lenght = $table_info->length;
$field = $table_info->name; // nom du champ
$table =$table_info->table; // todo
$type = $table_info->type; // Text,integer,
$flag = $table_info->flags;//
if ($i<1)$v.=$field;
else $v.='xxx' . $field;
$i=$i+1;
}
$msg=' .liste le contenu des champs!';$this->msg=$msg;
$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
$this->arRowsHeadColumn= explode('xxx', $v);//split sur le -
// liste le contenu des champs
while ($line = mysqli_fetch_assoc($result)) {
array_push($this->arRows, (object)$line);//ajout objet.array au tableau resultat
$nbr=$nbr+1;
}
$msg=' .memo dans classe !';$this->msg=$msg;
$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
$this->nbr=$nbr;
//$this->rawData=$this->arRows;
//return $this->arRows;
$this->msgret=$conn->info;
return true;
}//fin execMysqlReq()
public function snd_response($stmt) {
// renvoi des donnees suivant le Accept demandé ------------------------------------
$msg="";$pgm=$this->pgm;$fonc='.snd_reponse()';$this->fonc=$fonc;
try{
$statusCode = 200;
$requestAccept = $_SERVER['HTTP_ACCEPT'];
// on renvoie le status-code{200;404;500} ..................
// et le content-type avec la meme valeur que le accept recu!
$this->setHttpHeaders($requestAccept, $statusCode);
if(strpos($this->stmt, 'select') !== false) {
// suivant Accept on encode la reponse .....................
if (strpos($requestAccept, 'application/json') !== false) {
$this->action='Select';
$response = $this->encodeJson2();
$msg=$requestAccept . ':'.$response;$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
echo $response;
} else if (strpos($requestAccept, 'application/xml') !== false) {
$response = $this->encodeXml2();
$msg=$requestAccept . ':'.$response;$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
echo $response;
} else if (strpos($requestAccept, 'text/html') !== false) {
//mise en tableau pendant la recup du result
$response = $this->encodeHtml2();
$msg=$requestAccept . ':'.$response;$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
echo $response;
} else if (strpos($requestAccept, '*/*') !== false) {
$response = $this->encodeTxt2();
$msg=$requestAccept . ':'.$response;$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
echo $response;
} else{
$response = $this->encodeTxt2();
$msg=$requestAccept . ':'.$response;$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
echo $response;
}
}
if(strpos($this->stmt, 'update') !== false || strpos($this->stmt, 'save') !== false ) {
// suivant Accept on encode la reponse .....................
if (strpos($requestAccept, 'application/json') !== false) {
$response = "{\"result\":\"".$this->msgret."\"}";
$msg=$requestAccept . ':'.$response;$ok=logmsg($this->pid,'log.txt',$msg, $pgm, $fonc);
echo $response;
} else if (strpos($requestAccept, 'application/xml') !== false) {
$response = "
| " . $etc . " | "; } $htmlResponse .= "||
| " . $key . " | "."" . $value . " | "; $htmlResponse .= "" . $value . " | "; } $htmlResponse .= "