Allright.. there is a bunch of things :
In view/js/projectorDialog.js I added :
var ReportPrintType ='';
//open the dialog with checkboxes
function openReportPrint (Type) {
ReportPrintType =Type;
if (formChangeInProgress) {
showAlert(i18n('alertOngoingChange'));
return;
}
top.dijit.byId("dialogReportPrint").show();
}
//close the dialog with checkboxes
function closeReportPrint (obj,idUser) {
top.dijit.byId("dialogReportPrint").hide();
saveCheckboxReportPrint(obj,idUser);
}
//save current state of checkboxes
function saveCheckboxReportPrint(obj,idUser){
var val = dojo.byId('column0').value;
var toStore=obj+";"+idUser;
val = eval(val);
for(i=1; i<val+1;i++){
var checkbox=dojo.byId('column'+i);
if(checkbox) {
if(checkbox.checked) {
var field=checkbox.value.split(';');
toStore=toStore + ";" + field[4];
}
}
}
var xhr = getXMLHttpRequest();
var toSend = encodeURIComponent(toStore);
xhr.open("GET", "../tool/saveCheckboxes.php?toStore=" + toSend , true);
xhr.send(null);
}
//pretty sure you're familiar with this
function getXMLHttpRequest() {
var xhr = null;
if (window.XMLHttpRequest || window.ActiveXObject) {
if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
} else {
xhr = new XMLHttpRequest();
}
} else {
alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
return null;
}
return xhr;
}
//computes witch so pdf export takes all page.
function egalizeWidth(width){
var SumWidth=0;
for (var i in width){
SumWidth = parseInt(SumWidth)+parseInt(width[i]);
}
for (var i in width){
width[i]=100*width[i]/SumWidth;
}
return width;
}
var layoutPrint ='';
//Executes the report (shows the print/pdf/csv)
function executeReportPrint(obj,idUser) {
layoutPrint ='';
var verif=0;
var val = dojo.byId('column0').value;
val = eval(val);
var width = {};
for(i=1; i<val+1;i++){
var checkbox=dojo.byId('column'+i);
if(checkbox) {
if(checkbox.checked) {
var field=checkbox.value.split(';');
width[field[0]]=field[2];
}
}
}
width = egalizeWidth(width);
for(i=1; i<val+1;i++){
var checkbox=dojo.byId('column'+i);
if(checkbox) {
if(checkbox.checked) {
var field=checkbox.value.split(';');
layoutPrint+='<th field="'+field[0]+'" formatter="'+field[3]+'" width="'+width[field[0]]+'%">'+field[1]+'</th> ';
verif=1;
}
}
}
if(verif==1){
var grid = dijit.byId("objectGrid");
if(grid.rowCount > 200) {
actionYes=function() {
if(ReportPrintType=='print') {
showPrint("../tool/jsonQuery.php", 'list');
} else if(ReportPrintType=='csv') {
showPrint("../tool/jsonQuery.php", 'list', null, 'csv');
} else if(ReportPrintType=='pdf') {
showPrint("../tool/jsonQuery.php", 'list', null, 'pdf');
} else {
showPrint("../tool/jsonQuery.php", 'list');
}
closeReportPrint (obj,idUser);
};
actionNo=function() { closeReportPrint (obj,idUser); };
showQuestion("<b>" + i18n('extracting') + " " + grid.rowCount + " " + i18n('lines')+".</b><br>" + i18n('longTraitment') + ".<br>" + i18n('wantToExtract'),actionYes,actionNo);
} else {
if(ReportPrintType=='print') {
showPrint("../tool/jsonQuery.php", 'list');
} else if(ReportPrintType=='csv') {
showPrint("../tool/jsonQuery.php", 'list', null, 'csv');
} else if(ReportPrintType=='pdf') {
showPrint("../tool/jsonQuery.php", 'list', null, 'pdf');
} else {
showPrint("../tool/jsonQuery.php", 'list');
}
closeReportPrint (obj,idUser);
}
} else {
showAlert(i18n('alertChooseOneAtLeast'));
}
}
//Check or uncheck all boxes
function checkReportPrint () {
var check = dojo.byId('checkUncheck').checked;
var val = dojo.byId('column0').value;
val = eval(val);
for(i=1; i<val+1;i++){
var checkbox=dijit.byId('column'+i);
if(checkbox) {
dijit.byId(checkbox).setValue(check);
}
}
}
In view/objectList.php :
<div id="dialogReportPrint" dojoType="dijit.Dialog" title="<?php echo i18n("dialogReportPrint");?>"
style=";margin-left: 0px;margin-top: 0px;">
<table style="width:100%;">
<?php
$idUser = $_SESSION['user']->id;
$query='SELECT checkboxes FROM printcheckbox WHERE `objclass`="'.$objectClass.'" AND `idUser`="'.$idUser.'";';
$result=Sql::query($query);
$line = Sql::fetchLine($result);
$checkboxDB=array();
while($line) {
$checkboxDB[]=$line;
$line = Sql::fetchLine($result);
}
if(count($checkboxDB)>0){
$checkboxDB=$checkboxDB[0]['checkboxes'];
$checkboxDB=explode(";",$checkboxDB);
}
$htmlresult="<br>";
$htmlresult.="<b>".i18n("chooseColumnPrint").' :</b><br><br>';
$htmlresult.='<tr>';
$htmlresult.='<form id="dialogPrintForm" name="dialogPrintForm">';
$FieldsArray=$obj->getFieldsArray();
foreach($FieldsArray as $key => $val) {
$FieldsArray[$key]=$obj->getColCaption($val);
if (substr($val,0,5)=='_col_') {
if (strlen($val)>8) {
$section=substr($val,9);
$FieldsArray[$key]=i18n('section' . ucfirst($section));
}
}
if(substr($FieldsArray[$key],0,1)=="["){
unset($FieldsArray[$key]);
continue;
}
}
$countFields=count($FieldsArray);
$htmlresult.='<input type="hidden" dojoType="dijit.form.TextBox" id="column0" name="column0" value="'.$countFields.'">';
$index=1;
$last_key = end($FieldsArray);
foreach($FieldsArray as $key => $val){
if(substr($key,0,5)=="_col_"){
if($val!=$last_key) {
$htmlresult.='<b>'.$val.'</b><br>';
}
} else if(substr($key,0,5)=="input"){
}else {
$checked='';
foreach($checkboxDB as $valchecked){
if($valchecked==$key){
$checked='checked';
}
}
$dataType = $obj->getDataType($key);
$dataLength = $obj->getDataLength($key);
$width=5;
$formatter='';
if ($key=='id') { // id
$formatter="numericFormatter";
$htmlresult.='<input type="checkbox" dojoType="dijit.form.CheckBox" id="column'.$index.'" name="column'.$index.'" value="'.$key.';'.$val.';'.$width.';'.$formatter.';'.$key.'" '.$checked.'>'.$val.'<br>';
} else if ($key=='password') { // PassWord
// nothing
} else if ($dataType=='date' and $val!=null and $val != '') { // Date
$formatter="dateFormatter";
$htmlresult.='<input type="checkbox" dojoType="dijit.form.CheckBox" id="column'.$index.'" name="column'.$index.'" value="'.$key.';'.$val.';'.$width.';'.$formatter.';'.$key.'" '.$checked.'>'.$val.'<br>';
} else if ($dataType=='datetime' and $val!=null and $val != '') { // Date and Time
$formatter="dateFormatter";
$htmlresult.='<input type="checkbox" dojoType="dijit.form.CheckBox" id="column'.$index.'" name="column'.$index.'" value="'.$key.';'.$val.';'.$width.';'.$formatter.';'.$key.'" '.$checked.'>'.$val.'<br>';
} else if ($dataType=='time' and $val!=null and $val != '') { // Time
$formatter="dateFormatter";
$htmlresult.='<input type="checkbox" dojoType="dijit.form.CheckBox" id="column'.$index.'" name="column'.$index.'" value="'.$key.';'.$val.';'.$width.';'.$formatter.';'.$key.'" '.$checked.'>'.$val.'<br>';
} else if ($key=='color' and $dataLength == 7 ) { // color
$formatter="colorFormatter";
$htmlresult.='<input type="checkbox" dojoType="dijit.form.CheckBox" id="column'.$index.'" name="column'.$index.'" value="'.$key.';'.$val.';'.$width.';'.$formatter.';'.$key.'" '.$checked.'>'.$val.'<br>';
} else if ($dataType=='int' and $dataLength==1) { // boolean
$formatter="booleanFormatter";
$htmlresult.='<input type="checkbox" dojoType="dijit.form.CheckBox" id="column'.$index.'" name="column'.$index.'" value="'.$key.';'.$val.';'.$width.';'.$formatter.';'.$key.'" '.$checked.'>'.$val.'<br>';
} else if ($dataLength > 100) { // Text Area (must reproduce BR, spaces, ...
$width=20;
$htmlresult.='<input type="checkbox" dojoType="dijit.form.CheckBox" id="column'.$index.'" name="column'.$index.'" value="'.$key.';'.$val.';'.$width.';'.$formatter.';'.$key.'" '.$checked.'>'.$val.'<br>';
} else if (substr($key,0,2)=='id' and $dataType=='int' and strlen($key)>2 and substr($key,2,1)==strtoupper(substr($key,2,1)) ) { // Idxxx
if(substr($key,2,strlen($key))=='Status') {
$formatter="colorNameFormatter";
$htmlresult.='<input type="checkbox" dojoType="dijit.form.CheckBox" id="column'.$index.'" name="column'.$index.'" value="'.'colorName'.substr($key,2,strlen($key)).';'.$val.';'.$width.';'.$formatter.';'.$key.'" '.$checked.'>'.$val.'<br>';
} else if(substr($key,2,strlen($key))=='Profile') {
$formatter="translateFormatter";
$htmlresult.='<input type="checkbox" dojoType="dijit.form.CheckBox" id="column'.$index.'" name="column'.$index.'" value="'.'name'.substr($key,2,strlen($key)).';'.$val.';'.$width.';'.$formatter.';'.$key.'" '.$checked.'>'.$val.'<br>';
} else {
$htmlresult.='<input type="checkbox" dojoType="dijit.form.CheckBox" id="column'.$index.'" name="column'.$index.'" value="'.'name'.substr($key,2,strlen($key)).';'.$val.';'.$width.';'.$formatter.';'.$key.'" '.$checked.'>'.$val.'<br>';
}
} else {
$htmlresult.='<input type="checkbox" dojoType="dijit.form.CheckBox" id="column'.$index.'" name="column'.$index.'" value="'.$key.';'.$val.';'.$width.';'.$formatter.';'.$key.'" '.$checked.'>'.$val.'<br>';
}
$index++;
}
}
$htmlresult.="<br>";
$htmlresult.='<input type="checkbox" dojoType="dijit.form.CheckBox" id="checkUncheck" name="checkUncheck" value="Check" onclick="checkReportPrint();" '.$checked.'><b>'.i18n("checkUncheckAll").'</b><br><br>';
echo $htmlresult;
?>
<tr>
<td>
<button align="left" dojoType="dijit.form.Button" id="dialogePrintSubmit" onclick="executeReportPrint('<?php echo $objectClass;?>','<?php echo $idUser;?>');">
<?php echo i18n("buttonOK");?>
</button>
</td><td>
<button align="right" dojoType="dijit.form.Button" onclick="closeReportPrint('<?php echo $objectClass;?>','<?php echo $idUser;?>');">
<?php echo i18n("buttonCancel");?>
</button>
<td>
</tr>
</form>
</tr>
</table>
</div>
Created the file tool/saveCheckboxes.php:
<?php
/** ===========================================================================
* This script stores checkboxes' states
*/
require_once "../tool/projector.php";
scriptLog(' ->/tool/jsonQuery.php');
header("Content-Type: text/plain"); // Utilisation d'un header pour spécifier le type de contenu de la page. Ici, il s'agit juste de texte brut (text/plain).
$toStore = (isset($_GET["toStore"])) ? $_GET["toStore"] : NULL;
$toStore=explode(";",$toStore);
if(count($toStore)>1){
$objClass = $toStore[0];
$idUser = $toStore[1];
unset($toStore[0]);
unset($toStore[1]);
if(count($toStore)==0) {
$toStore='';
} else {
$toStore=implode(";",$toStore);
}
$query='SELECT objclass FROM printcheckbox WHERE `objclass`="'.$objClass.'" AND idUser="'.$idUser.'";';
$result=Sql::query($query);
$line = Sql::fetchLine($result);
$checkboxDB=array();
while($line) {
$checkboxDB[]=$line;
$line = Sql::fetchLine($result);
}
if(count($checkboxDB)>0){
$query ="UPDATE printcheckbox set checkboxes='".$toStore."' WHERE objclass='".$objClass."' AND idUser='".$idUser."';";
} else {
$query ="INSERT INTO printcheckbox (`objclass`,`checkboxes`,`idUser`) VALUES('".$objClass."','".$toStore."','".$idUser."')";
}
$result=Sql::query($query);
}
?>
Created table :
CREATE TABLE `${prefix}printcheckbox` (
`id` int(12) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
`objclass` varchar(50) DEFAULT NULL,
`idUser` int(12) unsigned DEFAULT NULL,
`checkboxes` varchar(500) DEFAULt NULL,
`idle` int(1) unsigned DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
Since the last time, I added the fact that it stores checkboxes states for each user.
Note : my queries do not take $prefix into account.