Rev 48 | Rev 73 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpclass GttCtrlActionGestion extends aControlleurAction {public function __construct(Registre $Registre){$Registre->ajouterEspace('Gestion', 'gestion');$Registre->ajouterSquelette('gestion', 'gestion.tpl.html');}public function executer(){$aso_gestion = array();$this->getRegistre()->setTitre('Gérer son temps');//+-------------------------------------------------------------------------------------------------+// GESTION DES CALENDRIERS//+-------------------------------------------------------------------------------------------------+// Initialisation des variables pour le calendrierif (!isset($_GET['annee'])) {$_GET['annee'] = date('Y');}if (!isset($_GET['mois'])) {$_GET['mois'] = date('m');}if (!isset($_GET['semaine'])) {$_GET['semaine'] = date('W');}if (!isset($_GET['jour'])) {$_GET['jour'] = date('d');}// Instanciation de la classe Calendrier France$Calendrier = new Calendrier($_GET['jour'], $_GET['semaine'], $_GET['mois'], $_GET['annee']);$tab_jours_feries = $Calendrier->getListeFeries();// Create an array of days which are "selected"// Used for Week::build() below$CalendrierJourCourrant = new Calendar_Week(date('Y'), date('m'), date('d'));$aso_gestion['jc']['jour'] = $CalendrierJourCourrant->thisDay();$aso_gestion['jc']['semaine'] = $CalendrierJourCourrant->thisWeek('n_in_year');$aso_gestion['jc']['mois'] = $CalendrierJourCourrant->thisMonth();$aso_gestion['jc']['mois_nom'] = $Calendrier->getNomMois($CalendrierJourCourrant->thisMonth());$aso_gestion['jc']['annee'] = $CalendrierJourCourrant->thisYear();$aso_gestion['jc_url'] = 'index.php?action='.GTT_ACTION_GESTION.'&annee='.$aso_gestion['jc']['annee'].'&mois='.$aso_gestion['jc']['mois'].'&semaine='.$aso_gestion['jc']['semaine'].'&jour='.$aso_gestion['jc']['jour'];$CalendrierJourCourrant->build();$CalendrierSemaineCourrante = $CalendrierJourCourrant->thisWeek('object');$CalendrierSemaineCourrante->build();$tab_jours = $CalendrierSemaineCourrante->fetchAll();$aso_gestion['sjc_1']['jour'] = $tab_jours[1]->thisDay();$aso_gestion['sjc_1']['mois'] = $Calendrier->getNomMois($tab_jours[1]->thisMonth());$aso_gestion['sjc_1']['annee'] = $tab_jours[1]->thisYear();$aso_gestion['sjc_7']['jour'] = $tab_jours[7]->thisDay();$aso_gestion['sjc_7']['mois'] = $Calendrier->getNomMois($tab_jours[7]->thisMonth());$aso_gestion['sjc_7']['annee'] = $tab_jours[7]->thisYear();$aso_gestion['selectedDays'] = array ($CalendrierJourCourrant);// Instruct month to build Week objects// Construction de l'objet mois$Month = new Calendar_Month_Weeks($_GET['annee'], $_GET['mois']);$Month->build();while ($Week = $Month->fetch()) {$Week->build($aso_gestion['selectedDays']);//echo '<pre>'.print_r($Month, true).'</pre>';$tab_semaine_jours = $Week->fetchAll();foreach ($tab_semaine_jours as $num => $Day) {$element = array();$element['annee'] = $Day->thisYear();$element['mois'] = $Day->thisMonth();$element['jour'] = $Day->thisDay();$element['jour_nom'] = $Calendrier->getNomJours($num);$element['url'] = 'index.php?action='.GTT_ACTION_GESTION.'&annee='.$Day->thisYear().'&mois='.$Day->thisMonth().'&jour='.$Day->thisDay();// Check to see if day is selectedif ($Day->isSelected()) {$element['class'] = 'jour_courrant';} else if ($Day->isEmpty()) {$element['class'] = 'jour_vide';} else {$element['class'] = 'jour';}foreach ($tab_jours_feries as $jour_ferie) {if ($Day->thisDay(true) == $jour_ferie) {$element['class'] = 'jour_ferie';}}$aso_gestion['elements'][$Week->thisWeek('n_in_year')][$num] = $element;}}// Construction de l'url pour les mois précédent/suivant$PMonth = $Month->prevMonth('object');$aso_gestion['url_mois_precedent'] = 'index.php?action='.GTT_ACTION_GESTION.'&annee='.$PMonth->thisYear().'&mois='.$PMonth->thisMonth().'&jour='.$PMonth->thisDay();$NMonth = $Month->nextMonth('object');$aso_gestion['url_mois_suivant'] = 'index.php?action='.GTT_ACTION_GESTION.'&annee='.$NMonth->thisYear().'&mois='.$NMonth->thisMonth().'&jour='.$NMonth->thisDay();$aso_gestion['mois']['mois'] = $Calendrier->getNomMois($Month->thisMonth());$aso_gestion['mois']['annee'] = $Month->thisYear();// Construction de l'url pour les semaines précédente/suivante$Week = new Calendar_Week($_GET['annee'], $_GET['mois'], $_GET['jour']);$aso_gestion['s'] = $Week->thisWeek('n_in_year');$PWeek = $Week->prevWeek('object');$aso_gestion['url_semaine_precedente'] = 'index.php?action='.GTT_ACTION_GESTION.'&annee='.$PWeek->thisYear().'&mois='.$PWeek->thisMonth().'&jour='.$PWeek->thisDay();$url_sc_param_date = '&annee='.$Week->thisYear().'&mois='.$Week->thisMonth().'&jour='.$Week->thisDay();$aso_gestion['url_semaine_courante'] = 'index.php?action='.GTT_ACTION_GESTION.$url_sc_param_date;$NWeek = $Week->nextWeek('object');$aso_gestion['url_semaine_suivante'] = 'index.php?action='.GTT_ACTION_GESTION.'&annee='.$NWeek->thisYear().'&mois='.$NWeek->thisMonth().'&jour='.$NWeek->thisDay();$Week->build();$aso_jours = array();foreach($Week->fetchAll() as $num => $j) {$aso_gestion['sj_'.$num]['jour'] = $j->thisDay();$aso_gestion['sj_'.$num]['mois'] = $Calendrier->getNomMois($j->thisMonth());$aso_gestion['sj_'.$num]['annee'] = $j->thisYear();$aso_gestion['sj_'.$num]['mysql'] = $aso_gestion['sj_'.$num]['annee'].'-'.sprintf("%02s", $j->thisMonth()).'-'.sprintf("%02s", $aso_gestion['sj_'.$num]['jour']);$aso_jours[$aso_gestion['sj_'.$num]['mysql']] = $num;$aso_tps_w_vide[$num] = '';}//+-------------------------------------------------------------------------------------------------+// GESTION DES PROJETS//+-------------------------------------------------------------------------------------------------+// Récupération des infos sur l'utilisateur$aso_gestion['conges_payes'] = $GLOBALS['_GTT_']['Utilisateur']->getCongesPayes();$aso_gestion['rtt'] = $GLOBALS['_GTT_']['Utilisateur']->getQuotaHeuresSupp();$aso_gestion['tps_w'] = $GLOBALS['_GTT_']['Utilisateur']->getTempsDeTravailJour();// Récupération des projets sur lesquels l'utilisateur travaille$UtilsateurAProjet = new UtilisateurAProjet();$tab_uap = $UtilsateurAProjet->consulter(UtilisateurAProjet::GUAP_UTILISATEUR, $GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur());// Si nous avons des données...$aso_gestion['bool_projets'] = false;if ($tab_uap && count($tab_uap) >= 1) {$aso_gestion['bool_projets'] = true;$tab_projet_id = array();foreach ($tab_uap as $uap) {$tab_projet_id[] = $uap->getIdProjet();}// Récupération du temps de travail pour un utilisateur à une date donnée$TravailProjet = new TravailProjet();$cmd = TravailProjet::GTP_ID_UTILISATEUR_DATE_DEB_FIN;$param = array($GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur(), $aso_gestion['sj_1']['mysql'], $aso_gestion['sj_7']['mysql']);$tab_tp = $TravailProjet->consulter($cmd, $param);if ($tab_tp && count($tab_tp) == 1) {$tab_tp = array($tab_tp);}// Récupération des infos sur les projets de l'utilisateur$aso_gestion['totaux'] = $aso_tps_w_vide;$Projet = new Projet();$tab_p = $Projet->consulter(Projet::GP_ID_LIST, array(implode(',', $tab_projet_id)));foreach ($tab_p as $Projet) {// Récupération de la catégorie du projet$ProjetCategorie = new ProjetCategorie();$cmd = ProjetCategorie::GPC_ID;$param = $Projet->getCeCategorie();$Categorie = $ProjetCategorie->consulter($cmd, $param);// Nous vérifions le temps de travail pour ce projet pour la semaine courrante$aso_tps_w = $aso_tps_w_vide;if (!isset($aso_gestion['categorie_totaux'][$Categorie->getLibelle()])) {$aso_gestion['categorie_totaux'][$Categorie->getLibelle()] = $aso_tps_w_vide;}if ($tab_tp) {foreach ($tab_tp as $TP) {if ($TP->getIdProjet() == $Projet->getIdProjet()) {$num = $aso_jours[$TP->getIdDateTravail()];$aso_tps_w[$num] = $TP->getDuree();$aso_gestion['categorie_totaux'][$Categorie->getLibelle()][$num] += $TP->getDuree();$aso_gestion['totaux'][$num] += $TP->getDuree();}}}// Stockage des infos nécessaire pour l'affichage$aso_gestion['preferences'][$Categorie->getLibelle()][] = array('id' => $Projet->getIdProjet(),'valeur' => $Projet->getIdProjet(),'nom' => $Projet->getNomProjet(),'date' => $aso_tps_w);}}//+-------------------------------------------------------------------------------------------------+// GESTION DES ABSENCES//+-------------------------------------------------------------------------------------------------+// Récupération des motifs d'absence$AbsenceMotif = new AbsenceMotif();$cmd = AbsenceMotif::GAM_TOUS;$tab_am = $AbsenceMotif->consulter($cmd);if ($tab_am && count($tab_am) == 1) {$tab_am = array($tab_am);}// Récupération des absences pour un utilisateur à une date donnée$Absence = new Absence();$cmd = Absence::GA_ID_UTILISATEUR_DATE_DEB_FIN;$param = array($GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur(), $aso_gestion['sj_1']['mysql'], $aso_gestion['sj_7']['mysql']);$tab_a = $Absence->consulter($cmd, $param);// Si nous avons des absences...if ($tab_a && count($tab_a) == 1) {$tab_a = array($tab_a);}$aso_gestion['ab_total'] = $aso_tps_w_vide;if ($tab_am) {foreach ($tab_am as $AM) {$aso_gestion['ab_libelle'][$AM->getIdAbsenceMotif()] = $AM->getLibelle();$aso_gestion['ab'][$AM->getIdAbsenceMotif()] = $aso_tps_w_vide;if ($tab_a) {foreach ($tab_a as $A) {if ($A->getIdAbsenceMotif() == $AM->getIdAbsenceMotif()) {$num = $aso_jours[$A->getIdDateAbsence()];$aso_gestion['ab'][$AM->getIdAbsenceMotif()][$num] = $A->getDuree();$aso_gestion['ab_total'][$num] += $A->getDuree();$aso_gestion['totaux'][$num] += $A->getDuree();}}}}}// Création de l'url de réponse du formulaire$aso_gestion['url_gestion_valider'] = 'index.php?action='.GTT_ACTION_GESTION_VALIDER.$url_sc_param_date;//echo '<pre>ici '.print_r($aso_gestion['ab'], true).'la</pre>';$this->getRegistre()->ajouterDonnee('gestion', $aso_gestion);}public function verifierValider(){}public function executerValider(){//echo '<pre>'.print_r($_POST, true).'</pre>';// Récupération des info sur la semaine courrante$Week = new Calendar_Week($_GET['annee'], $_GET['mois'], $_GET['jour']);$Week->build();$aso_jours = array();$aso_semaine = array();foreach($Week->fetchAll() as $num => $j) {$aso_semaine[$num]['mysql'] = $j->thisYear().'-'.sprintf("%02s", $j->thisMonth()).'-'.sprintf("%02s", $j->thisDay());$aso_jours[$aso_semaine[$num]['mysql']] = $num;}// Récupération du temps de travail pour un utilisateur à une date donnée$TravailProjet = new TravailProjet();$cmd = TravailProjet::GTP_ID_UTILISATEUR_DATE_DEB_FIN;$param = array($GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur(), $aso_semaine[1]['mysql'], $aso_semaine[7]['mysql']);$tab_tp = $TravailProjet->consulter($cmd, $param);if ($tab_tp && count($tab_tp) == 1) {$tab_tp = array($tab_tp);}// Ajout ou Mise à jour des durées de travailif (isset($_POST['pr'])) {foreach($_POST['pr'] as $projet_id => $jours) {//echo '<pre>'.print_r($jours, true).'</pre>';foreach($jours as $jour_num => $nbr_heure) {$bool_ajouter = true;if (!empty($tab_tp)) {foreach ($tab_tp as $TP) {if ($TP->getIdDateTravail() == $aso_semaine[$jour_num]['mysql']) {if ($TP->getIdProjet() == $projet_id) {$bool_ajouter = false;if ($TP->getDuree() != $nbr_heure) {if (empty($nbr_heure)) {$TP->supprimer();} else {$TP->setDuree($nbr_heure);$TP->modifier();}}}}}}if ($bool_ajouter && !empty($nbr_heure)) {$TP = new TravailProjet();$TP->setDuree((float)$nbr_heure);$TP->setIdUtilisateur($GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur());$TP->setIdProjet($projet_id);$TP->setIdDateTravail((string)$aso_semaine[$jour_num]['mysql']);$TP->ajouter();}}}}// Récupération des absences pour un utilisateur à une date donnée$Absence = new Absence();$cmd = Absence::GA_ID_UTILISATEUR_DATE_DEB_FIN;$param = array($GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur(), $aso_semaine[1]['mysql'], $aso_semaine[7]['mysql']);$tab_a = $Absence->consulter($cmd, $param);if ($tab_a && count($tab_a) == 1) {$tab_a = array($tab_a);}// Ajout ou Mise à jour des durées d'absences pour congés payésif (isset($_POST['ab'])) {//echo '<pre>'.print_r($_POST['ab'], true).'</pre>';foreach($_POST['ab'] as $ab_id => $tab_num_j) {foreach($tab_num_j as $num_j => $ab_duree) {$bool_ajouter = true;if (!empty($tab_a)) {foreach ($tab_a as $A) {if ($A->getIdDateAbsence() == $aso_semaine[$num_j]['mysql']) {if ($A->getIdAbsenceMotif() == $ab_id) {$bool_ajouter = false;if ($A->getDuree() != $ab_duree) {if (empty($ab_duree)) {$A->supprimer();} else {$A->setDuree($ab_duree);$A->modifier();}}}}}}if ($bool_ajouter && !empty($ab_duree)) {$A = new Absence();$A->setDuree((float)$ab_duree);$A->setIdUtilisateur($GLOBALS['_GTT_']['Utilisateur']->getIdUtilisateur());$A->setIdAbsenceMotif($ab_id);$A->setIdDateAbsence((string)$aso_semaine[$num_j]['mysql']);$A->ajouter();}}}}// Action suivante$this->setSuivant('__defaut__');}}?>