151 |
} |
} |
152 |
} |
} |
153 |
} |
} |
|
if(!$this->canAccess()) { |
|
|
// |
|
|
$message_class = "error"; |
|
|
$message = _("Droits insuffisants. Vous n'avez pas suffisament de ". |
|
|
"droits pour acceder a cette page."); |
|
|
$this->f->addToMessage($message_class, $message); |
|
|
|
|
|
// |
|
|
$this->f->setFlag(NULL); |
|
|
$this->f->display(); |
|
|
|
|
|
// Arrêt du script |
|
|
die(); |
|
|
} |
|
154 |
} |
} |
155 |
|
|
156 |
|
|
397 |
$this->addToLog("supprimer() - end", EXTRA_VERBOSE_MODE); |
$this->addToLog("supprimer() - end", EXTRA_VERBOSE_MODE); |
398 |
} |
} |
399 |
|
|
400 |
|
/** |
401 |
|
* Surcharge de la méthode formulaire afin d'y ajouter |
402 |
|
* la méthode de verification d'accès à l'élément |
403 |
|
* |
404 |
|
*/ |
405 |
|
function formulaire($enteteTab, $validation, $maj, &$db, $postVar, $aff, |
406 |
|
$DEBUG = false, $idx, $premier = 0, $recherche = "", |
407 |
|
$tricol = "", $idz = "", $selectioncol = "", |
408 |
|
$advs_id = "", $valide = "", $retour = "", $actions = array(), |
409 |
|
$extra_parameters = array()) { |
410 |
|
|
411 |
|
// Mode debug desactive |
412 |
|
$DEBUG = false; |
413 |
|
// Affectation des parametres dans un tableau associatif pour le |
414 |
|
// stocker en attribut de l'objet |
415 |
|
$parameters = array( |
416 |
|
"aff" => $aff, |
417 |
|
"validation" => $validation, |
418 |
|
"maj" => $maj, |
419 |
|
"idx" => $idx, |
420 |
|
"premier" => $premier, |
421 |
|
"recherche" => $recherche, |
422 |
|
"tricol" => $tricol, |
423 |
|
"idz" => $idz, |
424 |
|
"selectioncol" => $selectioncol, |
425 |
|
"advs_id" => $advs_id, |
426 |
|
"valide" => $valide, |
427 |
|
"retour" => $retour, |
428 |
|
); |
429 |
|
// Affectation du tableau precedant dans l'attribut 'parameters' |
430 |
|
$this->setParameters($parameters); |
431 |
|
// Affectation du tableau passe en parametre dans l'attribut 'parameters' |
432 |
|
$this->setParameters($extra_parameters); |
433 |
|
// Ouverture de la balise form si pas en consultation |
434 |
|
if($maj!=3) { |
435 |
|
echo "\n<!-- ########## START DBFORM ########## -->\n"; |
436 |
|
echo "<form"; |
437 |
|
echo " method=\"post\""; |
438 |
|
echo " name=\"f1\""; |
439 |
|
echo " action=\""; |
440 |
|
echo $this->getDataSubmit(); |
441 |
|
echo "\""; |
442 |
|
echo ">\n"; |
443 |
|
} |
444 |
|
// Compatibilite anterieure - On decremente la variable validation |
445 |
|
$this->setParameter("validation", $this->getParameter("validation") - 1); |
446 |
|
// Instanciation de l'objet formulaire |
447 |
|
$this->form = new $this->om_formulaire($enteteTab, $this->getParameter("validation"), $maj, $this->champs, $this->val, $this->longueurMax); |
448 |
|
// Valorisation des variables formulaires |
449 |
|
$this->setVal($this->form, $maj, $this->getParameter("validation"), $this->db, $DEBUG); |
450 |
|
$this->setType($this->form, $maj); |
451 |
|
$this->setLib($this->form, $maj); |
452 |
|
$this->setTaille($this->form, $maj); |
453 |
|
$this->setMax($this->form, $maj); |
454 |
|
$this->setSelect($this->form, $maj, $this->db, $DEBUG); |
455 |
|
$this->setOnchange($this->form, $maj); |
456 |
|
$this->setOnkeyup($this->form, $maj); |
457 |
|
$this->setOnclick($this->form, $maj); |
458 |
|
$this->setGroupe($this->form, $maj); |
459 |
|
$this->setRegroupe($this->form, $maj); |
460 |
|
$this->setLayout($this->form, $maj); |
461 |
|
$this->setRequired($this->form, $maj); |
462 |
|
// |
463 |
|
$this->form->recupererPostvar($this->champs, $this->getParameter("validation"), $postVar, $DEBUG); |
464 |
|
// Si le formulaire a ete valide |
465 |
|
if ($this->getParameter("validation") > 0) { |
466 |
|
// Appel des methodes en fonction du mode pour inserer, modifier ou |
467 |
|
// supprimer l'objet de/dans la base de donnees. |
468 |
|
if ($maj == 2) { |
469 |
|
// (MODE 'delete') |
470 |
|
$db->autoCommit(false); |
471 |
|
$this->supprimer($this->form->val, $this->db, $DEBUG); |
472 |
|
$db->commit(); |
473 |
|
} else { |
474 |
|
if ($maj == 1) { |
475 |
|
// (MODE 'update') |
476 |
|
$db->autoCommit(false); |
477 |
|
$this->modifier($this->form->val, $this->db, $DEBUG); |
478 |
|
$db->commit(); |
479 |
|
} else { |
480 |
|
// (MODE 'insert') |
481 |
|
$db->autoCommit(false); |
482 |
|
$this->ajouter($this->form->val, $this->db, $DEBUG) ; |
483 |
|
$db->commit(); |
484 |
|
} |
485 |
|
} |
486 |
|
} |
487 |
|
// Desactivation du verrou |
488 |
|
$this->deverrouille($this->getParameter("validation")); |
489 |
|
// Si le formulaire a ete valide |
490 |
|
if ($this->getParameter("validation") > 0) { |
491 |
|
// Affichage du message avant d'afficher le formulaire |
492 |
|
$this->message(); |
493 |
|
// Si le formulaire est valide |
494 |
|
if ($this->correct) { |
495 |
|
// Affichage du bouton retour |
496 |
|
$this->retour($premier, $recherche, $tricol); |
497 |
|
} |
498 |
|
} |
499 |
|
//Test les droits d'accès à l'élément. |
500 |
|
if(!$this->canAccess() AND $maj != 0) { |
501 |
|
// |
502 |
|
$message_class = "error"; |
503 |
|
$message = _("Droits insuffisants. Vous n'avez pas suffisament de ". |
504 |
|
"droits pour acceder a cette page."); |
505 |
|
$this->f->addToMessage($message_class, $message); |
506 |
|
|
507 |
|
// |
508 |
|
$this->f->setFlag(NULL); |
509 |
|
$this->f->display(); |
510 |
|
|
511 |
|
// Arrêt du script |
512 |
|
die(); |
513 |
|
} |
514 |
|
// Affichage du contenu du formulaire |
515 |
|
$this->form->entete(); |
516 |
|
|
517 |
|
// Portlet d'actions contextuelles |
518 |
|
if ($maj == 3 and !empty($actions)) { |
519 |
|
|
520 |
|
// On surcharge les actions |
521 |
|
if (!empty($this->actions_sup)) { |
522 |
|
$actions = array_merge($actions, $this->actions_sup); |
523 |
|
} |
524 |
|
|
525 |
|
// On retient seulement les actions de l'utilisateur |
526 |
|
$user_actions = array(); |
527 |
|
foreach($actions as $action => $conf) { |
528 |
|
|
529 |
|
// Verification des droits |
530 |
|
if (!isset($conf['rights']) |
531 |
|
or $this->f->isAccredited($conf['rights']['list'], |
532 |
|
$conf['rights']['operator'])) { |
533 |
|
|
534 |
|
// Preparation du tri |
535 |
|
if (!isset($conf['ordre']) or empty($conf['ordre'])) { |
536 |
|
|
537 |
|
$this->actions_order[] = array($action); |
538 |
|
} else if (!key_exists($conf['ordre'], |
539 |
|
$this->actions_order)) { |
540 |
|
|
541 |
|
$this->actions_order[$conf['ordre']] = array($action); |
542 |
|
} else { |
543 |
|
|
544 |
|
$this->actions_order[$conf['ordre']][] = $action; |
545 |
|
asort($this->actions_order[$conf['ordre']]); |
546 |
|
} |
547 |
|
|
548 |
|
// Verification de l'action (vide ou non) |
549 |
|
if (!empty($conf['lien']) and $conf['lien'] != '#') { |
550 |
|
$user_actions[$action] = $conf; |
551 |
|
} |
552 |
|
} |
553 |
|
} |
554 |
|
|
555 |
|
ksort($this->actions_order); |
556 |
|
|
557 |
|
// Affichage du portlet d'actions s'il existe des actions |
558 |
|
if (!empty($user_actions)) { |
559 |
|
$this->form->afficher_portlet($idx, $user_actions, |
560 |
|
$this->actions_order); |
561 |
|
} |
562 |
|
} |
563 |
|
|
564 |
|
$this->form->afficher($this->champs, $this->getParameter("validation"), $DEBUG, $this->correct); |
565 |
|
$this->form->enpied(); |
566 |
|
|
567 |
|
// Affichage du bouton et du bouton retour |
568 |
|
echo "\n<!-- ########## START FORMCONTROLS ########## -->\n"; |
569 |
|
echo "<div class=\"formControls\">\n"; |
570 |
|
if($maj!=3) { |
571 |
|
$this->bouton($maj); |
572 |
|
} |
573 |
|
$this->retour($premier, $recherche, $tricol); |
574 |
|
echo "</div>\n"; |
575 |
|
echo "<!-- ########## END FORMCONTROLS ########## -->\n"; |
576 |
|
// Fermeture de la balise form |
577 |
|
if($maj!=3) { |
578 |
|
echo "</form>\n"; |
579 |
|
echo "<!-- ########## END DBFORM ########## -->\n"; |
580 |
|
} |
581 |
|
// Sous formulaire interne et zone supplementaire |
582 |
|
if ($maj == 1) { |
583 |
|
$this->sousformulaireinterne(get_class($this), $idx, $this->db); |
584 |
|
} else { |
585 |
|
if ($maj == 0 and isset($this->valF[$this->clePrimaire]) and $this->valF[$this->clePrimaire] != "") { |
586 |
|
$this->sousformulaireinterne(get_class($this), $this->valF[$this->clePrimaire], $this->db); |
587 |
|
} |
588 |
|
} |
589 |
|
} |
590 |
|
/** |
591 |
|
* Surcharge de la méthode sousformulaire afin d'y ajouter |
592 |
|
* la méthode de verification d'accès à l'élément |
593 |
|
* |
594 |
|
*/ |
595 |
|
function sousformulaire($enteteTab, $validation, $maj, &$db, $postVar, |
596 |
|
$premiersf, $DEBUG, $idx, $idxformulaire, |
597 |
|
$retourformulaire, $typeformulaire, $objsf, |
598 |
|
$tricolsf, $retour= "", $actions = array()) { |
599 |
|
|
600 |
|
/* |
601 |
|
$enteteTab: libelle d entete du formulaire |
602 |
|
$styleform: style des controles du formulaires |
603 |
|
$maj : 0 ajouter / 1 mise a jour / 2 suppression |
604 |
|
$db : connexion base de donnees |
605 |
|
$aff : appel formulaire |
606 |
|
$DEBUG : 0= normal / 1= debugage |
607 |
|
$idx : valeur de l'id de la table mouvement (pour relancer la requete |
608 |
|
$idxformulaire : idx du formulaire |
609 |
|
$retourformulaire : nom du formulaire de retour |
610 |
|
*/ |
611 |
|
//passage tricolonne soustableau par $tricolsf |
612 |
|
$DEBUG=0; |
613 |
|
|
614 |
|
// Affectation des parametres dans un tableau associatif pour le |
615 |
|
// stocker en attribut de l'objet |
616 |
|
$parameters = array( |
617 |
|
"validation" => $validation, |
618 |
|
"maj" => $maj, |
619 |
|
"idx" => $idx, |
620 |
|
"idxformulaire" => $idxformulaire, |
621 |
|
"premiersf" => $premiersf, |
622 |
|
"tricolsf" => $tricolsf, |
623 |
|
"retour" => $retour, |
624 |
|
"retourformulaire" => $retourformulaire, |
625 |
|
"typeformulaire" => $typeformulaire, |
626 |
|
"objsf" => $objsf, |
627 |
|
); |
628 |
|
// Affectation du tableau precedant dans l'attribut 'parameters' |
629 |
|
$this->setParameters($parameters); |
630 |
|
|
631 |
|
//sousformulaire genere par ajax [sub form with ajax] |
632 |
|
$datasubmit=""; |
633 |
|
|
634 |
|
// sans idx [without idx] |
635 |
|
if ($idx=="]") { |
636 |
|
|
637 |
|
// ajouter [add] |
638 |
|
if($maj==0) { |
639 |
|
$datasubmit="../scr/sousform.php?obj=$objsf&premiersf=$premiersf&retourformulaire=$retourformulaire&idxformulaire=$idxformulaire&trisf=$tricolsf". |
640 |
|
"&validation=$validation&retour=$retour"; |
641 |
|
} |
642 |
|
|
643 |
|
// avec idx [with idx] |
644 |
|
} else { |
645 |
|
|
646 |
|
// modifier [modify] |
647 |
|
if($maj==1) { |
648 |
|
$datasubmit="../scr/sousform.php?obj=$objsf&premiersf=$premiersf&retourformulaire=$retourformulaire&idxformulaire=$idxformulaire&trisf=$tricolsf". |
649 |
|
"&validation=$validation&idx=$idx&retour=$retour"; |
650 |
|
|
651 |
|
// supprimer [delete] |
652 |
|
} else { |
653 |
|
$datasubmit="../scr/sousform.php?obj=$objsf&premiersf=$premiersf&retourformulaire=$retourformulaire&idxformulaire=$idxformulaire&trisf=$tricolsf". |
654 |
|
"&validation=$validation&ids=1&idx=$idx&retour=tab"; |
655 |
|
} |
656 |
|
} |
657 |
|
if($maj!=3) { |
658 |
|
echo "<form name=\"f2\" action=\"\" methode=\"post\" "; |
659 |
|
echo "onsubmit=\"affichersform('".$objsf."', '$datasubmit', this);return false;\" >"; |
660 |
|
} |
661 |
|
$validation--; // compatibilite anterieure |
662 |
|
$form = new $this->om_formulaire($enteteTab, $validation, $maj, $this->champs,$this->val,$this->longueurMax); |
663 |
|
$this->form = $form; |
664 |
|
//-------------------------------------------------------------------------- |
665 |
|
// valorisation des variables formulaires [form variables values] |
666 |
|
//-------------------------------------------------------------------------- |
667 |
|
$this->setValsousformulaire($form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire,$db,$DEBUG); |
668 |
|
$this->setType($form,$maj) ; |
669 |
|
$this->setLib($form,$maj) ; |
670 |
|
$this->setTaille($form,$maj) ; |
671 |
|
$this->setMax($form,$maj) ; |
672 |
|
$this->setSelect($form,$maj,$db,$DEBUG) ; |
673 |
|
$this->setOnchange($form,$maj) ; |
674 |
|
$this->setOnkeyup($form,$maj) ; |
675 |
|
$this->setOnclick($form,$maj) ; |
676 |
|
$this->setGroupe($form,$maj) ; |
677 |
|
$this->setRegroupe($form,$maj) ; |
678 |
|
$this->setLayout($form, $maj); |
679 |
|
$this->setRequired($form, $maj); |
680 |
|
//-------------------------------------------------------------------------- |
681 |
|
// affichage du formulaire |
682 |
|
// ------------------------------------------------------------------------- |
683 |
|
|
684 |
|
$form->recupererPostvarsousform($this->champs,$validation,$postVar,$DEBUG); |
685 |
|
|
686 |
|
// validation ============================================================== |
687 |
|
if ($validation>0) { |
688 |
|
if ($maj==2){ |
689 |
|
$db->autoCommit(false); |
690 |
|
$this->supprimer($form->val,$db,$DEBUG); |
691 |
|
$db->commit() ; |
692 |
|
} else { |
693 |
|
if ($maj==1) { |
694 |
|
$db->autoCommit(false); |
695 |
|
$this->modifier($form->val,$db,$DEBUG); |
696 |
|
$db->commit() ; |
697 |
|
} else { |
698 |
|
$db->autoCommit(false); |
699 |
|
$this->ajouter($form->val,$db,$DEBUG,$idx) ; |
700 |
|
$db->commit() ; |
701 |
|
} |
702 |
|
} |
703 |
|
} |
704 |
|
|
705 |
|
$this->deverrouille($validation); |
706 |
|
if ($validation > 0) { |
707 |
|
$this->message(); |
708 |
|
if ($this->correct) { |
709 |
|
$this->retoursousformulaire($idxformulaire,$retourformulaire,$form->val,$objsf,$premiersf,$tricolsf, $validation, $idx,$maj, $retour); |
710 |
|
} |
711 |
|
} |
712 |
|
//Test les droits d'accès à l'élément. |
713 |
|
if(!$this->canAccess() AND $maj != 0) { |
714 |
|
// |
715 |
|
$message_class = "error"; |
716 |
|
$message = _("Droits insuffisants. Vous n'avez pas suffisament de ". |
717 |
|
"droits pour acceder a cette page."); |
718 |
|
$this->f->addToMessage($message_class, $message); |
719 |
|
|
720 |
|
// |
721 |
|
$this->f->setFlag(NULL); |
722 |
|
$this->f->display(); |
723 |
|
|
724 |
|
// Arrêt du script |
725 |
|
die(); |
726 |
|
} |
727 |
|
$form->entete(); |
728 |
|
|
729 |
|
// Portlet d'actions contextuelles |
730 |
|
if ($maj == 3 and !empty($actions)) { |
731 |
|
|
732 |
|
// On surcharge les actions |
733 |
|
if (!empty($this->actions_sup)) { |
734 |
|
$actions = array_merge($actions, $this->actions_sup); |
735 |
|
} |
736 |
|
|
737 |
|
// On retient seulement les actions de l'utilisateur |
738 |
|
$user_actions = array(); |
739 |
|
foreach($actions as $action => $conf) { |
740 |
|
|
741 |
|
// Verification des droits |
742 |
|
if (!isset($conf['rights']) |
743 |
|
or $this->f->isAccredited($conf['rights']['list'], |
744 |
|
$conf['rights']['operator'])) { |
745 |
|
|
746 |
|
// Preparation du tri |
747 |
|
if (!isset($conf['ordre']) or empty($conf['ordre'])) { |
748 |
|
|
749 |
|
$this->actions_order[] = array($action); |
750 |
|
} else if (!key_exists($conf['ordre'], |
751 |
|
$this->actions_order)) { |
752 |
|
|
753 |
|
$this->actions_order[$conf['ordre']] = array($action); |
754 |
|
} else { |
755 |
|
|
756 |
|
$this->actions_order[$conf['ordre']][] = $action; |
757 |
|
asort($this->actions_order[$conf['ordre']]); |
758 |
|
} |
759 |
|
|
760 |
|
// Verification de l'action (vide ou non) |
761 |
|
if (!empty($conf['lien']) and $conf['lien'] != '#') { |
762 |
|
$user_actions[$action] = $conf; |
763 |
|
} |
764 |
|
} |
765 |
|
} |
766 |
|
|
767 |
|
ksort($this->actions_order); |
768 |
|
|
769 |
|
// Affichage du portlet d'actions s'il existe des actions |
770 |
|
if (!empty($user_actions)) { |
771 |
|
$this->form->afficher_portlet($idx, $user_actions, |
772 |
|
$this->actions_order, $objsf); |
773 |
|
} |
774 |
|
} |
775 |
|
|
776 |
|
$form->afficher($this->champs,$validation,$DEBUG,$this->correct); |
777 |
|
$form->enpied(); |
778 |
|
|
779 |
|
echo "<div class=\"formControls\">"; |
780 |
|
if($maj!=3) { |
781 |
|
$this->boutonsousformulaire($datasubmit,$maj,$form->val); |
782 |
|
} |
783 |
|
$this->retoursousformulaire($idxformulaire,$retourformulaire,$form->val,$objsf,$premiersf,$tricolsf, $validation, $idx,$maj, $retour); |
784 |
|
echo "</div>\n"; |
785 |
|
if($maj!=3) { |
786 |
|
echo "</form>"; |
787 |
|
} |
788 |
|
// --------------------- |
789 |
|
// sousformulaireinterne |
790 |
|
// --------------------- |
791 |
|
//if($maj==1) { |
792 |
|
// $this->sousformulaireinterne(get_class($this),$idx,$db); |
793 |
|
//} |
794 |
|
if($maj==1) { // moyen_com |
795 |
|
$this->sousformulaireinterne(get_class($this),$idx,$db); |
796 |
|
}else{ |
797 |
|
if ($maj == 0 and isset($this->valF[$this->clePrimaire]) |
798 |
|
and $this->valF[$this->clePrimaire] != "") { |
799 |
|
$this->sousformulaireinterne(get_class($this),$this->valF[$this->clePrimaire],$db); |
800 |
|
} |
801 |
|
} |
802 |
|
} |
803 |
|
|
804 |
/** |
/** |
805 |
* Methode de verification de l'unicite d'une valeur pour chaque elements du tableau unique_key, |
* Methode de verification de l'unicite d'une valeur pour chaque elements du tableau unique_key, |
859 |
* @param string $value valeur à inserer dans la colonne |
* @param string $value valeur à inserer dans la colonne |
860 |
*/ |
*/ |
861 |
function isUnique($champ,$value) { |
function isUnique($champ,$value) { |
862 |
//Test sur un groupe de champs |
//Test sur un groupe de champs |
863 |
if(is_array($champ) and is_array($value)) { |
if(is_array($champ) and is_array($value)) { |
864 |
$sql = 'SELECT count(*) FROM '.DB_PREFIXE.$this->table." WHERE ".implode(" = ? AND ",$champ)." = ?"; |
$sql = 'SELECT count(*) FROM '.DB_PREFIXE.$this->table." WHERE ".implode(" = ? AND ",$champ)." = ?"; |
865 |
} else { |
} else { |
866 |
//Test sur un champ |
//Test sur un champ |
867 |
$sql = 'SELECT count(*) FROM '.DB_PREFIXE.$this->table." WHERE ".$champ." = ?"; |
$sql = 'SELECT count(*) FROM '.DB_PREFIXE.$this->table." WHERE ".$champ." = ?"; |
868 |
} |
} |
869 |
if($this->getParameter('maj')) { |
if($this->getParameter('maj')) { |