évolution code pour version 1.3 de paheko

correction décalage date affichée
This commit is contained in:
Jean-Christophe Engel 2023-09-30 20:56:38 +02:00
parent d46d7b00dc
commit b236ef5f71
28 changed files with 162 additions and 140 deletions

View File

@ -10,15 +10,12 @@ use Paheko\Utils;
$csrf_key = 'cat_create';
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
{
// try to add new category and if error catched add it in form
try
{
$form->runIf(f('save') && !$form->hasErrors(), function() use ($cat, $form) {
try {
$cat->add([
'name' => ucfirst(f('name'))
]);
Utils::redirect(PLUGIN_URL . 'categories/index.php');
Utils::redirect(Utils::getSelfURL());
}
catch (\RuntimeException $e)
{
@ -30,7 +27,8 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$form->addError($e->getMessage());
}
}
}
}, $csrf_key);
// get the list of all categories and send it to template

View File

@ -26,7 +26,7 @@ $eqmt = new Equipment;
list($eqmts_owned, $eqmts_no_owned, $eqmts_just_listed) = $eqmt->AllListsAll($eqmts);
$return_link = PLUGIN_URL . 'categories/index.php';
$return_link = Utils::plugin_url() . 'categories/index.php';
// send to template the category's name and all lists of its equipment

View File

@ -18,7 +18,8 @@ if (!$cat_requested) {
// check if edit form is submitted
$csrf_key = 'edit_category_' . $cat_requested->id;
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$form->runIf(f('save') && !$form->hasErrors(),
function() use($cat, $cat_requested, $form)
{
// try to edit category selected and if error catched add it in form
try
@ -26,7 +27,7 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$cat->edit($cat_requested->id, [
'name' => ucfirst(f('name'))
]);
Utils::redirect(PLUGIN_URL . 'categories/index.php');
Utils::redirect(Utils::plugin_url() . 'categories/index.php');
}
catch (\RuntimeException $e)
{
@ -38,9 +39,9 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$form->addError($e->getMessage());
}
}
}
});
$cancel_link = PLUGIN_URL . 'categories/index.php';
$cancel_link = Utils::plugin_url() . 'categories/index.php';
// send all to template
$tpl->assign(compact('cat_requested', 'csrf_key', 'cancel_link'));

View File

@ -18,13 +18,14 @@ if (!$cat_requested) {
$csrf_key = 'delete_category_' . $cat_requested->id;
if (f('delete') && $form->check($csrf_key) && !$form->hasErrors())
$form->runIf(f('delete') && !$form->hasErrors(),
function() use ($cat, $cat_requested, $form)
{
try
{
// try to delete category selected and if error catched add it in form
$cat->delete($cat_requested->id);
Utils::redirect(PLUGIN_URL . 'categories/index.php');
Utils::redirect(Utils::plugin_url() . 'categories/index.php');
}
catch (\RuntimeException $e)
{
@ -36,9 +37,9 @@ if (f('delete') && $form->check($csrf_key) && !$form->hasErrors())
$form->addError($e->getMessage());
}
}
}
});
$cancel_link = PLUGIN_URL . 'categories/index.php';
$cancel_link = Utils::plugin_url() . 'categories/index.php';
// send to template the category requested

View File

@ -19,7 +19,7 @@ $eqmt_cat = $cat->get($eqmt_requested->category_id);
$eqmt_requested->category = $eqmt_cat->name;
$mvts = $mvt->AllEqmtMovements($eqmt_requested->id);
$return_link = PLUGIN_URL . 'index.php';
$return_link = Utils::plugin_url() . 'index.php';
// send all to template
$tpl->assign(compact('eqmt_requested', 'mvts', 'return_link'));

View File

@ -26,7 +26,8 @@ $selected_cat = $eqmt_requested->category_id;
// check if edit form is submitted
$csrf_key = 'edit_equipment_' . $eqmt_requested->id;
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$form->runIf (f('save') && !$form->hasErrors(),
function () use ($eqmt, $eqmt_requested)
{
// try to edit equipment selected and if error catched add it in form
try
@ -35,7 +36,7 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
'category_id' => (int) f('category_id'),
'designation' => ucfirst(strtolower(f('designation'))),
]);
Utils::redirect(PLUGIN_URL . 'index.php');
Utils::redirect(Utils::plugin_url() . 'index.php');
}
catch (\RuntimeException $e)
{
@ -47,9 +48,9 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$form->addError($e->getMessage());
}
}
}
});
$cancel_link = PLUGIN_URL . 'index.php';
$cancel_link = Utils::plugin_url() . 'index.php';
// send all to template
$tpl->assign(compact('eqmt_requested', 'cats', 'selected_cat', 'csrf_key', 'cancel_link'));

View File

@ -22,7 +22,8 @@ $selected_cat = $cats[0]->id;
// check if add form is submitted
$csrf_key = 'add_entry';
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$form->runIf(f('save') && !$form->hasErrors(),
function () use ($mvt, $form)
{
// try to add new equipment, get his id, add new entry
// and if error catched add it in form
@ -46,7 +47,7 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
'mvt_date' => $mvt_date_format,
'additional_comment' => f('additional_comment'),
]);
Utils::redirect(PLUGIN_URL . 'mouvements/entrees/index.php');
Utils::redirect(Utils::plugin_url() . 'mouvements/entrees/index.php');
}
catch (\RuntimeException $e)
{
@ -61,7 +62,7 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$selected_kind = f('kind');
$selected_cat = f('category_id');
}
}
});
// make default date (now)
$default_date = new \DateTime;
@ -71,7 +72,7 @@ $comment_placeholder = "ex: don reçu de la part de...";
// make cancel link, legend for the title of the form
// and the template name for equipment to use in form
$cancel_link = PLUGIN_URL . 'mouvements/entrees/index.php';
$cancel_link = Utils::plugin_url() . 'mouvements/entrees/index.php';
$legend_part = "non répertorié";
$tpl_materiel_name = "non_repertorie";

View File

@ -12,7 +12,8 @@ use Paheko\Utils;
// check if add form is submitted
$csrf_key = 'add_entry';
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$form->runIf(f('save') && !$form->hasErrors(),
function () use ($mvt)
{
// make the entry date in the good format
$mvt_date_format = date_create_from_format(
@ -26,8 +27,8 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
'mvt_date' => $mvt_date_format,
'additional_comment' => f('additional_comment'),
]);
Utils::redirect(PLUGIN_URL . 'mouvements/entrees/index.php');
}
Utils::redirect(Utils::plugin_url() . 'mouvements/entrees/index.php');
});
// get the list of all equipments ordered by category
$eqmt = new Equipment;
@ -45,7 +46,7 @@ $comment_placeholder = "ex: don reçu de la part de...";
// make cancel link, legend for the title of the form
// and the template name for equipment to use in form
$cancel_link = PLUGIN_URL . 'mouvements/entrees/index.php';
$cancel_link = Utils::plugin_url() . 'mouvements/entrees/index.php';
$legend_part = "répertorié";
$tpl_materiel_name = "repertorie";

View File

@ -17,7 +17,8 @@ $selected_eqmt = "";
// check if add form is submitted
$csrf_key = 'add_entry';
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$form->runIf(f('save') && !$form->hasErrors(),
function() use ($mvt, $eqmt, $selected_eqmt, $form)
{
$eqmt_id = f('equipment_id');
$eqmt_number = (int) f('equipment_number');
@ -35,7 +36,7 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
'mvt_date' => $mvt_date_format,
'additional_comment' => f('additional_comment'),
]);
Utils::redirect(PLUGIN_URL . 'mouvements/entrees/index.php');
Utils::redirect(Utils::plugin_url() . 'mouvements/entrees/index.php');
} else
{
// not possible, add error to form
@ -45,7 +46,7 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
// keep the datas submitted as selected
$selected_eqmt = $eqmt_id;
}
}
});
// make default date (now)
$default_date = new \DateTime;
@ -55,7 +56,7 @@ $comment_placeholder = "ex: retour de prêt...";
// make cancel link, legend for the title of the form
// and the template name for equipment to use in form
$cancel_link = PLUGIN_URL . 'mouvements/entrees/index.php';
$cancel_link = Utils::plugin_url() . 'mouvements/entrees/index.php';
$legend_part = "en retour de location / prêt";
$tpl_materiel_name = "retour";

View File

@ -21,7 +21,8 @@ $eqmt = new Equipment;
$csrf_key = 'delete_entry_' . $entry_to_delete->id;
if (f('delete') && $form->check($csrf_key) && !$form->hasErrors())
$form->runIf(f('delete') && !$form->hasErrors(),
function() use ($mvt, $eqmt, $entry_to_delete)
{
// delete the movement required
$mvt->delete($entry_to_delete->id);
@ -33,8 +34,8 @@ if (f('delete') && $form->check($csrf_key) && !$form->hasErrors())
}
catch (\RuntimeException $e){
}
Utils::redirect(PLUGIN_URL . 'mouvements/entrees/index.php');
}
Utils::redirect(Utils::plugin_url() . 'mouvements/entrees/index.php');
});
$corresponding_eqmt = $eqmt->get($entry_to_delete->equipment_id);
@ -42,7 +43,7 @@ $corresponding_eqmt = $eqmt->get($entry_to_delete->equipment_id);
if ($mvt->PossibilityDeleteEntry($entry_to_delete))
{
// it's possible
$cancel_link = PLUGIN_URL . 'mouvements/entrees/index.php';
$cancel_link = Utils::plugin_url() . 'mouvements/entrees/index.php';
// construct string to send to template
$entry_string = (string) $entry_to_delete->equipment_number . " " . $corresponding_eqmt->designation . " à la date du " . date_create_from_format(
"Y-m-d", $entry_to_delete->mvt_date)->format("d/m/y");

View File

@ -15,7 +15,8 @@ $selected_eqmt = "";
// check if add form is submitted
$csrf_key = 'add_output';
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$form->runIf (f('save') && !$form->hasErrors(),
function() use ($mvt, $eqmt, $selected_eqmt, $form)
{
$eqmt_id = f('equipment_id');
$eqmt_number = (int) f('equipment_number');
@ -33,7 +34,7 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
'mvt_date' => $mvt_date_format,
'additional_comment' => f('additional_comment'),
]);
Utils::redirect(PLUGIN_URL . 'mouvements/sorties/index.php');
Utils::redirect(Utils::plugin_url() . 'mouvements/sorties/index.php');
} else
{
// not possible, add error to form
@ -43,7 +44,7 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
// keep the datas submitted as selected
$selected_eqmt = $eqmt_id;
}
}
});
// get list of borrowed equipments ordered by category
$eqmts_by_cat = $eqmt->ListAllBorrowedByCategory();
@ -56,7 +57,7 @@ $comment_placeholder = "ex: matériel rendu...";
// make cancel link, legend for the title of the form
// and the template name for equipment to use in form
$cancel_link = PLUGIN_URL . 'mouvements/sorties/index.php';
$cancel_link = Utils::plugin_url() . 'mouvements/sorties/index.php';
$legend_part = "emprunté";
$tpl_materiel_name = "emprunte";

View File

@ -22,7 +22,8 @@ $selected_kind = $kinds[0];
// check if add form is submitted
$csrf_key = 'add_output';
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$form->runIf(f('save') && !$form->hasErrors(),
function() use ($mvt, $eqmt)
{
$eqmt_id = f('equipment_id');
$eqmt_number = (int) f('equipment_number');
@ -40,7 +41,7 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
'mvt_date' => $mvt_date_format,
'additional_comment' => f('additional_comment'),
]);
Utils::redirect(PLUGIN_URL . 'mouvements/sorties/index.php');
Utils::redirect(Utils::plugin_url() . 'mouvements/sorties/index.php');
} else
{
// not possible, add error to form
@ -51,7 +52,7 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$selected_eqmt = $eqmt_id;
$selected_kind = f('kind');
}
}
});
// make default date (now)
$default_date = new \DateTime;
@ -61,7 +62,7 @@ $comment_placeholder = "ex: don fait à...";
// make cancel link, legend for the title of the form
// and the template name for equipment to use in form
$cancel_link = PLUGIN_URL . 'mouvements/sorties/index.php';
$cancel_link = Utils::plugin_url() . 'mouvements/sorties/index.php';
$legend_part = "en stock disponible";
$tpl_materiel_name = "stock_disponible";

View File

@ -19,12 +19,13 @@ if (!$output_to_delete)
// check if delete form is submitted
$csrf_key = 'delete_output_' . $output_to_delete->id;
if (f('delete') && $form->check($csrf_key) && !$form->hasErrors())
$form->runIf (f('delete') && !$form->hasErrors(),
function () use ($mvt)
{
// delete the movement required
$mvt->delete($output_to_delete->id);
Utils::redirect(PLUGIN_URL . 'mouvements/sorties/index.php');
}
Utils::redirect(Utils::plugin_url() . 'mouvements/sorties/index.php');
});
$eqmt = new Equipment;
$corresponding_eqmt = $eqmt->get($output_to_delete->equipment_id);
@ -33,7 +34,7 @@ $corresponding_eqmt = $eqmt->get($output_to_delete->equipment_id);
if ($mvt->PossibilityDeleteOutput($output_to_delete))
{
// it's possible
$cancel_link = PLUGIN_URL . 'mouvements/sorties/index.php';
$cancel_link = Utils::plugin_url() . 'mouvements/sorties/index.php';
// construct string to send to template
$output_string = (string) $output_to_delete->equipment_number . " " . $corresponding_eqmt->designation . " à la date du " . date_create_from_format(
"Y-m-d", $output_to_delete->mvt_date)->format("d/m/y");

View File

@ -1,5 +1,5 @@
<!-- title -->
{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id}
{include file="_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id}
<!-- -->
<!-- nav bar -->
<nav class="tabs">

View File

@ -37,5 +37,5 @@
</table>
<!-- -->
<!-- footer -->
{include file="admin/_foot.tpl"}
{include file="_foot.tpl"}
<!-- -->

View File

@ -78,5 +78,5 @@
<!-- -->
{linkbutton label="Retour" shape="export" href=$return_link}
<!-- footer -->
{include file="admin/_foot.tpl"}
{include file="_foot.tpl"}
<!-- -->

View File

@ -18,5 +18,5 @@
</form>
<!-- -->
<!-- footer -->
{include file="admin/_foot.tpl"}
{include file="_foot.tpl"}
<!-- -->

View File

@ -9,5 +9,5 @@
}
<!-- -->
<!-- footer -->
{include file="admin/_foot.tpl"}
{include file="_foot.tpl"}
<!-- -->

View File

@ -26,7 +26,14 @@
<tbody>
{foreach from=$mvts item="mvt"}
<tr>
<?php
$mvt_date = date("d/m/Y", strtotime($mvt->mvt_date));
?>
{*
<td>{$mvt.mvt_date|date_format:'%d/%m/%y'}</td>
Erreur : dates décalées d'un jour (en arrière)
*}
<td>{$mvt_date}</td>
{if $mvt.side}
<td>Sortie</td>
{else}
@ -43,5 +50,5 @@
<!-- -->
{linkbutton label="Retour" shape="export" href=$return_link}
<!-- footer -->
{include file="admin/_foot.tpl"}
{include file="_foot.tpl"}
<!-- -->

View File

@ -115,5 +115,5 @@
{/foreach}
<!-- -->
<!-- footer -->
{include file="admin/_foot.tpl"}
{include file="_foot.tpl"}
<!-- -->

View File

@ -26,5 +26,5 @@
</form>
<!-- -->
<!-- footer -->
{include file="admin/_foot.tpl"}
{include file="_foot.tpl"}
<!-- -->

View File

@ -5,5 +5,5 @@
{include file="%smouvements/formulaire_mouvement.tpl"|args:$plugin_tpl legend="entrée d'un matériel %s"|args:$legend_part tpl_materiel_name=$tpl_materiel_name kinds=$kinds selected_kind=$selected_kind default_date=$default_date label_date="Date d'entrée" tpl_materiel_path="entrees" comment_placeholder=$comment_placeholder csrf_key=$csrf_key cancel_link=$cancel_link}
<!-- -->
<!-- footer -->
{include file="admin/_foot.tpl"}
{include file="_foot.tpl"}
<!-- -->

View File

@ -13,5 +13,5 @@
{include file="%smouvements/tableau_mouvements.tpl"|args:$plugin_tpl mvts=$mvts del_href="supprimer_entree.php?id=%d"}
<!-- -->
<!-- footer -->
{include file="admin/_foot.tpl"}
{include file="_foot.tpl"}
<!-- -->

View File

@ -9,5 +9,5 @@
}
<!-- -->
<!-- footer -->
{include file="admin/_foot.tpl"}
{include file="_foot.tpl"}
<!-- -->

View File

@ -5,5 +5,5 @@
{include file="%smouvements/formulaire_mouvement.tpl"|args:$plugin_tpl legend="sortie d'un matériel %s"|args:$legend_part tpl_materiel_name=$tpl_materiel_name kinds=$kinds selected_kind=$selected_kind default_date=$default_date label_date="Date de sortie" tpl_materiel_path="sorties" comment_placeholder=$comment_placeholder csrf_key=$csrf_key cancel_link=$cancel_link}
<!-- -->
<!-- footer -->
{include file="admin/_foot.tpl"}
{include file="_foot.tpl"}
<!-- -->

View File

@ -12,5 +12,5 @@
{include file="%smouvements/tableau_mouvements.tpl"|args:$plugin_tpl mvts=$mvts del_href="supprimer_sortie.php?id=%d"}
<!-- -->
<!-- footer -->
{include file="admin/_foot.tpl"}
{include file="_foot.tpl"}
<!-- -->

View File

@ -9,5 +9,5 @@
}
<!-- -->
<!-- footer -->
{include file="admin/_foot.tpl"}
{include file="_foot.tpl"}
<!-- -->

View File

@ -12,7 +12,14 @@
<tbody>
{foreach from=$mvts item="mvt"}
<tr>
<?php
$mvt_date = date("d/m/Y", strtotime($mvt->mvt_date));
?>
{*
<td>{$mvt.mvt_date|date_format:'%d/%m/%y'}</td>
Erreur : dates décalées d'un jour (en arrière)
*}
<td>{$mvt_date}</td>
<td>{$mvt.kind}</td>
<td class="num">{$mvt.equipment_number}</td>
<td>{$mvt.equipment}</td>