From ca2677ccc779498f49c01533f1667f14410276d5 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 15 Sep 2010 10:07:04 +0000 Subject: [PATCH] --- .../Controlleur/class.extranet.core.php | 67 ++++++++++--------- .../Controlleur/class.extranet.url.php | 10 ++- .../DAO/class.extranet.dao.fichier.php | 21 +++++- .../DAO/class.extranet.dao.projet.php | 1 - inc/extranet/Metier/class.extranet.projet.php | 1 - 5 files changed, 63 insertions(+), 37 deletions(-) diff --git a/inc/extranet/Controlleur/class.extranet.core.php b/inc/extranet/Controlleur/class.extranet.core.php index af5c2bb77..d5cecedd6 100644 --- a/inc/extranet/Controlleur/class.extranet.core.php +++ b/inc/extranet/Controlleur/class.extranet.core.php @@ -107,6 +107,8 @@ class extranetCore extends cubeCore { return; } + $this->views->dropAllViews(); + $db = new CubeDbStruct($this->con); // Table utilisateurs $db->utilisateurs->utilisateur_id('integer', 0, false); @@ -166,7 +168,6 @@ class extranetCore extends cubeCore { $db->projets->client('integer', 0, false); $db->projets->chef('integer', 0, false); $db->projets->status('integer', 1, false); - $db->projets->old('integer', 1, false); // Clés $db->projets->primary('pk_projets', 'projet_id'); $db->projets->index('index_projets_status', 'BTREE', 'status'); @@ -373,84 +374,84 @@ class extranetCore extends cubeCore { exit; } - $this->createView('equipiers', 'SELECT * FROM utilisateurs WHERE grade>=1'); - $this->createView('gerants', 'SELECT * FROM utilisateurs WHERE grade=2'); - // $this->createView('ws_top_revendeurs', 'SELECT * FROM utilisateurs WHERE ws_grade=3 AND ws_admin IN(SELECT utilisateur_id FROM equipiers)'); - $this->createView('ws_revendeurs', 'SELECT * FROM utilisateurs WHERE ws_grade=3'); - $this->createView('ws_facturables', 'SELECT * FROM utilisateurs WHERE ws_grade BETWEEN 0 AND 3 AND ws_admin IN(SELECT utilisateur_id FROM equipiers)'); - $this->createView('impayes_entreprises', 'SELECT SUM(total_ht) AS impaye, u.entreprise AS entreprise ' + $this->views->createView('equipiers', 'SELECT * FROM utilisateurs WHERE grade>=1'); + $this->views->createView('gerants', 'SELECT * FROM utilisateurs WHERE grade=2'); + // $this->views->createView('ws_top_revendeurs', 'SELECT * FROM utilisateurs WHERE ws_grade=3 AND ws_admin IN(SELECT utilisateur_id FROM equipiers)'); + $this->views->createView('ws_revendeurs', 'SELECT * FROM utilisateurs WHERE ws_grade=3'); + $this->views->createView('ws_facturables', 'SELECT * FROM utilisateurs WHERE ws_grade BETWEEN 0 AND 3 AND ws_admin IN(SELECT utilisateur_id FROM equipiers)'); + $this->views->createView('impayes_entreprises', 'SELECT SUM(total_ht) AS impaye, u.entreprise AS entreprise ' . 'FROM utilisateurs u LEFT JOIN projets p ON u.utilisateur_id=p.client LEFT JOIN factures f ON f.projet=p.projet_id ' . 'WHERE f.status=1 GROUP BY u.entreprise'); - $this->createView('entreprises_inter', 'SELECT e.*,' + $this->views->createView('entreprises_inter', 'SELECT e.*,' . 'SUM(f.total_ht) AS ca ' . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND grade=0 ' . 'LEFT JOIN projets p ON p.client=u.utilisateur_id ' . 'LEFT JOIN factures f ON f.projet=p.projet_id AND f.status IN(1,2) ' . 'GROUP BY e.entreprise_id'); - $this->createView('entreprises_vue', 'SELECT e.*,i.impaye AS impaye' + $this->views->createView('entreprises_vue', 'SELECT e.*,i.impaye AS impaye' . ' FROM entreprises_inter e LEFT JOIN impayes_entreprises i ON e.entreprise_id=i.entreprise'); - $this->createView('clients_entreprise', 'SELECT u.*,e.nom AS rs, e.adresse_facturation AS adresse_facturation ' + $this->views->createView('clients_entreprise', 'SELECT u.*,e.nom AS rs, e.adresse_facturation AS adresse_facturation ' . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND u.grade=0'); - $this->createView('clients', 'SELECT u.*,e.nom AS rs, e.adresse_facturation AS adresse_facturation, i.impaye, ' + $this->views->createView('clients', 'SELECT u.*,e.nom AS rs, e.adresse_facturation AS adresse_facturation, i.impaye, ' . 'SUM(f.total_ht) AS ca ' . 'FROM entreprises e LEFT JOIN impayes_entreprises i ON e.entreprise_id=i.entreprise LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND u.grade=0 LEFT JOIN projets p ON p.client=u.utilisateur_id LEFT JOIN factures f ON f.projet=p.projet_id AND f.status IN(1,2) ' . 'GROUP BY u.utilisateur_id'); - $this->createView('taches_vue', 'SELECT taches.tache_id,taches.nom,taches.categorie,taches.type,taches.budget,taches.projet,taches.taux_journalier, ' + $this->views->createView('taches_vue', 'SELECT taches.tache_id,taches.nom,taches.categorie,taches.type,taches.budget,taches.projet,taches.taux_journalier, ' . '(SUM(timereport.heures)/' . JOURNEE . ') AS jours_consommes, ((SUM(timereport.heures)/' . JOURNEE . ')/(taches.budget/taches.taux_journalier))*100 AS progression,(taches.budget/taches.taux_journalier) AS jours_prevus ' . 'FROM taches LEFT JOIN timereport ON taches.tache_id=timereport.tache_id ' . 'GROUP BY taches.tache_id'); - $this->createView('taches_projet', 'SELECT projet, ' + $this->views->createView('taches_projet', 'SELECT projet, ' . 'SUM(jours_prevus) AS jours_prevus,SUM(budget) AS budget,' . 'SUM(jours_consommes) AS jours_consommes, (SUM(jours_consommes)/SUM(jours_prevus))*100 AS progression ' . 'FROM taches_vue GROUP BY projet'); - $this->createView('devis_vue', 'SELECT devis.devis_id,devis.nom,devis.lignes,devis.status,devis.total_ht,devis.date_creation,devis.email,clients.utilisateur_id AS client_id,clients.rs AS client,equipiers.prenom AS createur,equipiers.utilisateur_id AS createur_id,devis.adresse ' + $this->views->createView('devis_vue', 'SELECT devis.devis_id,devis.nom,devis.lignes,devis.status,devis.total_ht,devis.date_creation,devis.email,clients.utilisateur_id AS client_id,clients.rs AS client,equipiers.prenom AS createur,equipiers.utilisateur_id AS createur_id,devis.adresse ' . 'FROM devis,clients,equipiers ' . 'WHERE devis.client=clients.utilisateur_id AND devis.createur=equipiers.utilisateur_id'); - $this->createView('factures_vue', 'SELECT factures.facture_id,factures.nom,factures.lignes,factures.status,factures.total_ht,factures.date_creation,factures.texte_complementaire,factures.informations_paiement,factures.date_paiement,factures.adresse,factures.avoir,' + $this->views->createView('factures_vue', 'SELECT factures.facture_id,factures.nom,factures.lignes,factures.status,factures.total_ht,factures.date_creation,factures.texte_complementaire,factures.informations_paiement,factures.date_paiement,factures.adresse,factures.avoir,' . 'projets.projet_id AS projet_id,projets.nom AS projet,projets.client_id AS client_id,projets.client as client,equipiers.prenom AS createur,equipiers.utilisateur_id AS createur_id ' . 'FROM factures,projets_vue projets,equipiers ' . 'WHERE factures.projet=projets.projet_id AND factures.createur=equipiers.utilisateur_id AND (factures.facture_id>=0 OR factures.status=1) '); - $this->createView('factures_payees', 'SELECT * FROM factures WHERE status=2'); - $this->createView('factures_valides', 'SELECT * FROM factures WHERE status=1 OR status=2'); - $this->createView('projets_inter', 'SELECT projets.projet_id,projets.nom,projets.status,projets.date_debut,projets.date_fin,projets.date_creation,projets.deadline,projets.devis,projets.old,' + $this->views->createView('factures_payees', 'SELECT * FROM factures WHERE status=2'); + $this->views->createView('factures_valides', 'SELECT * FROM factures WHERE status IN(1,2)'); + $this->views->createView('projets_inter', 'SELECT projets.projet_id,projets.nom,projets.status,projets.date_debut,projets.date_fin,projets.date_creation,projets.deadline,projets.devis,' . 'YEAR(FROM_UNIXTIME(projets.date_debut)) AS annee_debut,' . 'IF(YEAR(FROM_UNIXTIME(projets.date_fin))=1970,YEAR(NOW()),YEAR(FROM_UNIXTIME(projets.date_fin))) AS annee_fin,' . 'clients.rs AS client,equipiers.prenom AS chef,equipiers.utilisateur_id AS chef_id,clients.utilisateur_id AS client_id ' - . 'FROM projets,clients,equipiers ' - . 'WHERE clients.utilisateur_id=projets.client AND equipiers.utilisateur_id=projets.chef'); - $this->createView('projets_inter1', 'SELECT projets.*,taches.jours_prevus,taches.jours_consommes,taches.progression,taches.budget AS budget, ' + . 'FROM projets,clients_entreprise clients,equipiers ' + . 'WHERE clients.utilisateur_id=projets.client AND equipiers.utilisateur_id=projets.chef','TEMPTABLE'); + $this->views->createView('projets_inter1', 'SELECT projets.*,taches.jours_prevus,taches.jours_consommes,taches.progression,taches.budget AS budget, ' . 'IF(taches.budget>0,SUM(factures_valides.total_ht)/taches.budget,1) AS rapport_facturation, ' . 'SUM(factures_valides.total_ht) AS montant_facture ' . 'FROM projets_inter projets ' . 'LEFT JOIN taches_projet taches ON taches.projet=projets.projet_id ' . 'LEFT JOIN factures_valides ON factures_valides.projet=projets.projet_id ' - . 'GROUP BY projets.projet_id,factures_valides.projet'); - $this->createView('projets_vue', 'SELECT p.*,SUM(f.total_ht) AS montant_paye, ' + . 'GROUP BY projets.projet_id,factures_valides.projet','TEMPTABLE'); + $this->views->createView('projets_vue', 'SELECT p.*,SUM(f.total_ht) AS montant_paye, ' . 'IF(p.budget>0,SUM(f.total_ht)/p.budget,1) AS rapport_paiement ' . 'FROM projets_inter1 p ' . 'LEFT JOIN factures_payees f ON f.projet=p.projet_id ' - . 'GROUP BY p.projet_id'); - $this->createView('projets_timereport', 'SELECT * FROM projets_vue WHERE status=0'); - $this->createView('order_timereport', 'SELECT utilisateur_id,projet AS projet_id,MAX(date) AS derniere_activite FROM timereport,taches,projets WHERE taches.tache_id=timereport.tache_id AND taches.projet=projets.projet_id AND projets.status=0 GROUP BY utilisateur_id,taches.projet ORDER BY utilisateur_id ASC,MAX(date) DESC'); - $this->createView('ca', 'SELECT SUM(total_ht) AS ca, YEAR(FROM_UNIXTIME(date_creation)) annee FROM factures WHERE status IN(1,2) GROUP BY annee'); - $this->createView('ftpaccess', 'SELECT email AS userid,password AS passwd,utilisateur_id AS uid,' + . 'GROUP BY p.projet_id', 'TEMPTABLE'); + $this->views->createView('projets_timereport', 'SELECT * FROM projets_vue WHERE status=0'); + $this->views->createView('order_timereport', 'SELECT utilisateur_id,projet AS projet_id,MAX(date) AS derniere_activite FROM timereport,taches,projets WHERE taches.tache_id=timereport.tache_id AND taches.projet=projets.projet_id AND projets.status=0 GROUP BY utilisateur_id,taches.projet ORDER BY utilisateur_id ASC,MAX(date) DESC'); + $this->views->createView('ca', 'SELECT SUM(total_ht) AS ca, YEAR(FROM_UNIXTIME(date_creation)) annee FROM factures WHERE status IN(1,2) GROUP BY annee'); + $this->views->createView('ftpaccess', 'SELECT email AS userid,password AS passwd,utilisateur_id AS uid,' . '\'1000\' AS gid,CONCAT(\'' . FTPROOT . '\',utilisateur_id) AS homedir, \'/bin/false\' AS shell ' . 'FROM utilisateurs WHERE grade=0 ' . 'UNION ' . 'SELECT email AS userid,ws_password AS passwd,utilisateur_id AS uid,' . '\'1000\' AS gid,CONCAT(\'' . FTPROOT . '\',utilisateur_id) AS homedir, \'/bin/false\' AS shell ' . 'FROM utilisateurs WHERE grade=0 AND ws_password!=\'\''); - $this->createView('chiffres_categories', 'SELECT p.annee_fin AS annee, t.categorie, SUM(t.budget) AS ca ' + $this->views->createView('chiffres_categories', 'SELECT p.annee_fin AS annee, t.categorie, SUM(t.budget) AS ca ' . 'FROM projets_vue p, taches_vue t ' . 'WHERE t.projet=p.projet_id ' . 'GROUP BY t.categorie,p.annee_fin'); - $this->createView('temps_categories', 'SELECT p.annee_fin AS annee, t.categorie, SUM(t.jours_consommes) AS jours_consommes,SUM(t.jours_prevus) AS jours_prevus ' + $this->views->createView('temps_categories', 'SELECT p.annee_fin AS annee, t.categorie, SUM(t.jours_consommes) AS jours_consommes,SUM(t.jours_prevus) AS jours_prevus ' . 'FROM projets_vue p, taches_vue t ' . 'WHERE t.projet=p.projet_id ' . 'GROUP BY t.categorie,p.annee_fin'); - $this->createView('books_vue', 'SELECT b.*,b.proprietaire AS proprietaire_id,c.rs AS proprietaire_nom,c.ws_admin ' - . 'FROM books b, clients_entreprise c WHERE b.proprietaire=c.utilisateur_id'); - $this->createView('themes_vue', 'SELECT t.*,COUNT(b.book_id) AS nb_books,GROUP_CONCAT(DISTINCT b.book_id ORDER BY b.book_id ASC) AS books ' + $this->views->createView('books_vue', 'SELECT b.*,b.proprietaire AS proprietaire_id,c.rs AS proprietaire_nom,c.ws_admin ' + . 'FROM books b, clients_entreprise c WHERE b.proprietaire=c.utilisateur_id', 'TEMPTABLE'); + $this->views->createView('themes_vue', 'SELECT t.*,COUNT(*) AS nb_books,GROUP_CONCAT(DISTINCT b.book_id) AS books ' . 'FROM themes t ' . 'LEFT JOIN books b ON t.theme_id=b.theme ' . 'GROUP BY t.theme_id'); diff --git a/inc/extranet/Controlleur/class.extranet.url.php b/inc/extranet/Controlleur/class.extranet.url.php index 9a153ebb3..f21f5e64e 100644 --- a/inc/extranet/Controlleur/class.extranet.url.php +++ b/inc/extranet/Controlleur/class.extranet.url.php @@ -2122,8 +2122,9 @@ class extranetUrl { { $root = ROOT . '/cache/download/'; cubeFiles::scanRecursiveDir($root, $files); + $limit = TIME-7200; foreach($files as $f) { - if (filemtime($f) + 7200 < TIME) { + if (filemtime($f) < $limit) { unlink($f); } } @@ -2134,6 +2135,13 @@ class extranetUrl { } } } + + public static function deleteOldFilesFromFTP($args) + { + global $core; + $dao=new extranetDAOFichier($core->con); + $dao->deleteOldFiles(); + } } ?> \ No newline at end of file diff --git a/inc/extranet/DAO/class.extranet.dao.fichier.php b/inc/extranet/DAO/class.extranet.dao.fichier.php index 3913d0382..a02c6fa56 100644 --- a/inc/extranet/DAO/class.extranet.dao.fichier.php +++ b/inc/extranet/DAO/class.extranet.dao.fichier.php @@ -7,7 +7,7 @@ class extranetDAOFichier extends extranetDAO { $rel_path = str_replace(FTPROOT, '', $path); $fichier = new extranetFichier(); $fichier->contact = $infos['contact']; - $fichier->destinataire=$infos['destinataire']; + $fichier->destinataire = $infos['destinataire']; $e = explode('/', $path); $fichier->chemin = $path; $fichier->nom = array_pop($e); @@ -122,6 +122,25 @@ class extranetDAOFichier extends extranetDAO { unlink(FTPROOT . $path); } } + + public function deleteOldFiles() + { + $root = FTPROOT; + cubeFiles::scanRecursiveDir($root, $files); + + $limit = TIME-3600 * 24 * 60; // 60 days + + $size = 0; + + foreach($files as $f) { + if (filemtime($f) < $limit) { + fb(date('Y-m-d', filemtime($f)), $f); + $size += filesize($f); + unlink($f); + } + } + fb(files::size($size), 'Size of files deleted'); + } } ?> \ No newline at end of file diff --git a/inc/extranet/DAO/class.extranet.dao.projet.php b/inc/extranet/DAO/class.extranet.dao.projet.php index f9e992640..e87a1a516 100644 --- a/inc/extranet/DAO/class.extranet.dao.projet.php +++ b/inc/extranet/DAO/class.extranet.dao.projet.php @@ -27,7 +27,6 @@ class extranetDAOProjet extends extranetDAO { $projet->progression = round($r->progression); $projet->budget = round($r->budget); - $projet->old = $r->old; $projet->rapport_facturation = $r->rapport_facturation; $projet->rapport_paiement = $r->rapport_paiement; diff --git a/inc/extranet/Metier/class.extranet.projet.php b/inc/extranet/Metier/class.extranet.projet.php index 402fc42a2..e8cc8260b 100644 --- a/inc/extranet/Metier/class.extranet.projet.php +++ b/inc/extranet/Metier/class.extranet.projet.php @@ -22,7 +22,6 @@ class extranetProjet extends cubeMetier { protected $annee_fin; protected $rapport_facturation; protected $rapport_paiement; - protected $old; } ?> \ No newline at end of file -- 2.39.5