1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
|
<?php
include('./classes/date.php');
$current_date = new date();
if(isset($_GET['periode']))
{
$periode = htmlspecialchars($_GET['periode']);
}
else
{
$periode = date("Y-m");
}
$moisCrt = $current_date->getMonth($periode);
$anneeCrt = $current_date->getYear($periode);
//Y a un truc qui va pas ça va planter forcément à un moment
$precPeriode = date('Y-m', mktime(0, 0, 0, $moisCrt, 0, $anneeCrt));
$suivPeriode = date('Y-m', mktime(0, 0, 0, $moisCrt+2, 0, $anneeCrt));
$retour = $current_date->getCalendrier($periode);
$leCalendrier = $retour[0];
$totEnrg = $retour[1];
echo '<script type="text/javascript">';
?>
/*!
* Ext JS Library 3.1.1
* Copyright(c) 2006-2010 Ext JS, LLC
* licensing@extjs.com
* http://www.extjs.com/license
*/
Ext.onReady(function(){
/**
* Handler specified for the 'Available' column renderer
* @param {Object} value
*/
function formatDate(value){
return value ? value.dateFormat('M d, Y') : '';
}
// shorthand alias
var fm = Ext.form;
//create Data Store for ComboBox and create ComboBox
var storeProject = new Ext.data.Store({
// destroy the store if the grid is destroyed
autoDestroy: true,
autoLoad: true,
// load remote data using HTTP
url: './includes/project.php?c=<?php echo $_SESSION['company']; ?>',
// specify a XmlReader (coincides with the XML Ext.format of the returned data)
reader: new Ext.data.XmlReader({
// records will have a 'project' tag
record: 'project',
// use an Array of field definition objects to implicitly create a Record constructor
fields: [
{name: 'projectId'},
{name: 'projectName'}
]
}),
sortInfo: {field:'projectName', direction:'ASC'}
});
var storeDiscipline = new Ext.data.Store({
// destroy the store if the grid is destroyed
autoDestroy: true,
autoLoad: false,
// load remote data using HTTP
url: './includes/discipline.php',
// specify a XmlReader (coincides with the XML Ext.format of the returned data)
reader: new Ext.data.XmlReader({
// records will have a 'discipline' tag
record: 'discipline',
// use an Array of field definition objects to implicitly create a Record constructor
fields: [
{name: 'disciplineId'},
{name: 'disciplineName'}
]
}),
sortInfo: {field:'disciplineName', direction:'ASC'}
});
var storeActivity = new Ext.data.Store({
// destroy the store if the grid is destroyed
autoDestroy: true,
autoLoad: false,
// load remote data using HTTP
url: './includes/activity.php',
// specify a XmlReader (coincides with the XML Ext.format of the returned data)
reader: new Ext.data.XmlReader({
// records will have a 'activity' tag
record: 'activity',
// use an Array of field definition objects to implicitly create a Record constructor
fields: [
{name: 'activityId'},
{name: 'activityName'}
]
}),
sortInfo: {field:'activityName', direction:'ASC'}
});
//ComboBox
var comboActivity = new Ext.form.ComboBox({
allowBlank: true,
lazyRender: true,
maxLength: 55,
width: 110,
editable: true,
emptyText: 'Select an activity',
mode: 'local',
triggerAction: 'all',
store: storeActivity,
valueField: "activityId",
displayField: "activityId"
});
var comboDiscipline = new Ext.form.ComboBox({
allowBlank: false,
lazyRender: true,
maxLength: 55,
width: 110,
editable: false,
emptyText: 'Select',
mode: 'local',
triggerAction: 'all',
store: storeDiscipline,
valueField: "disciplineId",
displayField: "disciplineId",
listeners: {
'select' : function(cmb, rec, idx) {
comboActivity.clearValue();
comboActivity.store.load({
params: {'discipline': comboDiscipline.getValue() }
});
}
}
});
var comboProject = new Ext.form.ComboBox({
allowBlank: false,
lazyRender: true,
maxLength: 55,
width: 110,
editable: false,
emptyText: 'Select',
mode: 'local',
triggerAction: 'all',
store: storeProject,
valueField: "projectId",
displayField: "projectId",
listeners: {
'select' : function(cmb, rec, idx) {
comboDiscipline.clearValue();
comboDiscipline.store.load({
params: {'project': comboProject.getValue() }
});
}
}
});
// the column model has information about grid columns
// dataIndex maps the column to the specific data field in
// the data store (created below)
var cm = new Ext.grid.ColumnModel({
// specify any defaults for each column
defaults: {
sortable: true // columns are not sortable by default
},
columns: [
//new Ext.grid.RowNumberer(),
{
id: 'projectId',
header: 'Project',
dataIndex: 'projectId',
width: 55,
// use shorthand alias defined above
editor: comboProject
//renderer: Ext.util.Format.comboRenderer(comboProject)
},{
id: 'disciplineId',
header: 'Discipline',
dataIndex: 'disciplineId',
width: 55,
// use shorthand alias defined above
editor: comboDiscipline
//renderer: Ext.util.Format.comboRenderer(comboDiscipline)
},{
id: 'activityId',
header: 'Activity',
dataIndex: 'activityId',
width: 55,
// use shorthand alias defined above
editor: comboActivity
//renderer: Ext.util.Format.comboRenderer(comboActivity)
},
<?php
foreach($leCalendrier as $cle => $element)
{
$numJ = $cle+1;
$numXml = 'i'.$numJ;
if($_SESSION['company'] != 5)
{
if(($element == 'Saturday') || ($element == 'Sunday'))
{
echo "{header: '$numJ',
id: '$numXml',
dataIndex: '$numXml',
width: 20,
type: 'float',
css:'background-color:#e6e6e6;',
summaryType: 'sum',
// use shorthand alias defined above
editor: new fm.TextField({
allowBlank: true
})}\n";
if($totEnrg != $cle)
{
echo ",";
}
}
else
{
echo "{header: '$numJ',
id: '$numXml',
dataIndex: '$numXml',
width: 20,
type: 'float',
summaryType: 'sum',
// use shorthand alias defined above
editor: new fm.TextField({
allowBlank: true
})}\n";
if($totEnrg != $cle)
{
echo ",";
}
}
}
else
{
if(($element == 'Friday') || ($element == 'Saturday'))
{
echo "{header: '$numJ',
id: '$numXml',
dataIndex: '$numXml',
width: 20,
type: 'float',
css:'background-color:#e6e6e6;',
summaryType: 'sum',
// use shorthand alias defined above
editor: new fm.TextField({
allowBlank: true
})}\n";
if($totEnrg != $cle)
{
echo ",";
}
}
else
{
echo "{header: '$numJ',
id: '$numXml',
dataIndex: '$numXml',
width: 20,
type: 'float',
summaryType: 'sum',
// use shorthand alias defined above
editor: new fm.TextField({
allowBlank: true
})}\n";
if($totEnrg != $cle)
{
echo ",";
}
}
}
}
?>
]
});
// create the Data Store
var store = new Ext.data.Store({
// destroy the store if the grid is destroyed
autoDestroy: true,
// load remote data using HTTP
url: './includes/plants.php?p=<?php echo $_SESSION['id']."&periode=".$periode; ?>',
// specify a XmlReader (coincides with the XML format of the returned data)
reader: new Ext.data.XmlReader({
// records will have a 'plant' tag
record: 'plant',
// use an Array of field definition objects to implicitly create a Record constructor
fields: [
// the 'name' below matches the tag name to read, except 'availDate'
// which is mapped to the tag 'availability'
{name: 'projectId', type: 'string'},
{name: 'activityId', type: 'string'},
{name: 'disciplineId', type: 'string'},
<?php
foreach($leCalendrier as $cle => $element)
{
$numJ = $cle+1;
$numXml = 'i'.$numJ;
echo "{name: '$numXml', type: 'float'}";
if($totEnrg != $cle)
{
echo ",";
}
}
?>
]
}),
sortInfo: {field:'projectId', direction:'ASC'}
});
var summary = new Ext.ux.grid.GridSummary();
// create the editor grid
var grid = new Ext.grid.EditorGridPanel({
store: store,
plugins: [summary],
cm: cm,
height: 380,
title: 'TimeSheet',
frame: true,
// specify the check column plugin on the grid so the plugin is initialized
clicksToEdit: 1,
tbar: [{
text: 'Add',
iconCls: 'silk-add',
handler: function(){
// access the Record constructor through the grid's store
var Plant = grid.getStore().recordType;
var p = new Plant();
grid.stopEditing();
store.insert(0, p);
grid.startEditing(0, 0);
},
scope: this
}, '-',{
text: 'Delete',
iconCls: 'silk-delete',
handler: function(){
var index = grid.getSelectionModel().getSelectedCell();
if (!index) {
return false;
}
var rec = store.getAt(index[0]);
store.remove(rec);
},
scope: this
}, '-']
});
// manually trigger the data store load
store.load({
// store loading is asynchronous, use a load listener or callback to handle results
callback: function(){
Ext.Msg.show({
title: 'Store Load Callback',
msg: 'All data were loaded, data available for processing',
modal: false,
icon: Ext.Msg.INFO,
buttons: Ext.Msg.OK
});
}
});
<?php
if(($_SESSION['company'] == 1) || ($_SESSION['company'] == 3))
{
echo "var cmTR = new Ext.grid.ColumnModel({
// specify any defaults for each column
defaults: {
sortable: true // columns are not sortable by default
},
columns: [
{
id: 'libelleId',
header: 'Libelle',
dataIndex: 'libelleId',
width: 145,
// use shorthand alias defined above
editor: new fm.TextField({
allowBlank: false,
disabled: true
})
},";
foreach($leCalendrier as $cle => $element)
{
$numJ = $cle+1;
$numXml = 'r'.$numJ;
if(($element == 'Saturday') || ($element == 'Sunday'))
{
echo "{header: '$numJ',
id: '$numXml',
dataIndex: '$numXml',
width: 20,
type: 'integer',
css:'background-color:#e6e6e6;',
summaryType: 'sum',
// use shorthand alias defined above
editor: new fm.TextField({
allowBlank: true,
disabled: true
})}\n";
if($totEnrg != $cle)
{
echo ",";
}
}
else
{
echo "{header: '$numJ',
id: '$numXml',
dataIndex: '$numXml',
width: 20,
type: 'integer',
summaryType: 'sum',
// use shorthand alias defined above
editor: new fm.TextField({
allowBlank: true
})}\n";
if($totEnrg != $cle)
{
echo ",";
}
}
}
echo "]
});
// create the Data Store
var storeTR = new Ext.data.Store({
// destroy the store if the grid is destroyed
autoDestroy: true,
// load remote data using HTTP
url: './includes/repas.php?p=".$_SESSION['id']."&periode=".$periode."',
// specify a XmlReader (coincides with the XML format of the returned data)
reader: new Ext.data.XmlReader({
// records will have a 'plant' tag
record: 'libelle',
// use an Array of field definition objects to implicitly create a Record constructor
fields: [
// the 'name' below matches the tag name to read, except 'availDate'
// which is mapped to the tag 'availability'
{name: 'libelleId', type: 'string'},";
foreach($leCalendrier as $cle => $element)
{
$numJ = $cle+1;
$numXml = 'r'.$numJ;
echo "{name: '$numXml', type: 'integer'}";
if($totEnrg != $cle)
{
echo ",";
}
}
echo "]
})
});
// create the editor grid
var gridTR = new Ext.grid.EditorGridPanel({
store: storeTR,
cm: cmTR,
height: 150,
title: 'Repas',
frame: true,
clicksToEdit: 1
});
// manually trigger the data store load
storeTR.load({
// store loading is asynchronous, use a load listener or callback to handle results
callback: function(){
Ext.Msg.show({
title: 'Store Load Callback',
msg: 'All data were loaded, data available for processing',
modal: false,
icon: Ext.Msg.INFO,
buttons: Ext.Msg.OK
});
}
});";
}
?>
var submit = function () {
var json ="";
var jsonTR ="";
form = formPanel.getForm();
<?php
if(($_SESSION['company'] == 1) || ($_SESSION['company'] == 3))
{
echo "storeTR.each(function(storeTR){
jsonTR += '|'+ storeTR.data.libelleId + ',' +";
foreach($leCalendrier as $cle => $element)
{
$numJ = $cle+1;
$numXml = 'r'.$numJ;
echo 'storeTR.data.'.$numXml;
if($totEnrg != $cle)
{
echo ' + "," +';
}
else
{
echo ';';
}
}
echo ';});';
}
?>
jsonTR += "|"
jsonTR = jsonTR.substring(1, jsonTR.length - 1);
store.each(function(store){
json += '|'+ store.data.projectId + "," + store.data.disciplineId + "," + store.data.activityId + "," +
<?php
foreach($leCalendrier as $cle => $element)
{
$numJ = $cle+1;
$numXml = 'i'.$numJ;
echo 'store.data.'.$numXml;
if($totEnrg != $cle)
{
echo ' + "," +';
}
else
{
echo ';';
}
}
?>
;
});
json += "|"
json = json.substring(1, json.length - 1);
var myParams = {
gridStore: json,
repasStore: jsonTR,
idPers: <?php echo $_SESSION['id']; ?>,
annee: <?php echo $anneeCrt; ?>,
mois: <?php echo $moisCrt; ?>
}
form.submit({
method: 'POST',
url: './includes/save-form.php',
//scope: formPanel,
params: myParams,
waitMsg: "Please wait...",
waitTitle: "Send" //will only be applicable if no waitMsgTarget specified
});
formPanel.maskDisabled = true;//True to mask the panel when it is disabled
}; // eo function submit
var formPanel = new Ext.form.FormPanel({
renderTo:'EditorGrid',
<?php
if(($_SESSION['company'] == 1) || ($_SESSION['company'] == 3))
{
echo 'items: [grid, gridTR],';
}
else
{
echo 'items: [grid],';
}
?>
labelWidth:0,
padding:0,
layout: 'anchor',
//use buttons config to specify buttons in the footer of a Panel
buttons: [{
formBind: true, //binds button to the monitorValid valid state
text: 'Save',
iconCls: 'icon-save',
handler: submit,
scope: this
}]
});
formPanel.doLayout();
});
<?php
echo '</script>
<h2><a href="https://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['PHP_SELF']), '/\\').'/index.php?page=timesheet&periode='.$precPeriode.'"><-</a> '.$periode.' <a href="https://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['PHP_SELF']), '/\\').'/index.php?page=timesheet&periode='.$suivPeriode.'">-></a></h2>
<div id="EditorGrid"></div>';
?> |
Partager