From: vincent@cubedesigners.com Date: Mon, 17 Jan 2011 15:16:05 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=74bbb606da8137105c4c9b2d15eceefcda7002bc;p=cubeextranet.git --- diff --git a/inc/commons/DAO/_common.php b/inc/commons/DAO/_common.php index 37a35d23c..47479840e 100644 --- a/inc/commons/DAO/_common.php +++ b/inc/commons/DAO/_common.php @@ -4,5 +4,6 @@ $__autoload['commonDAOUtilisateur'] = dirname(__FILE__) . '/class.common.dao.uti $__autoload['commonDAOEquipier'] = dirname(__FILE__) . '/class.common.dao.equipier.php'; $__autoload['commonDAOClient'] = dirname(__FILE__) . '/class.common.dao.client.php'; $__autoload['commonDAOEntreprise'] = dirname(__FILE__) . '/class.common.dao.entreprise.php'; +$__autoload['commonDAOFichier'] = dirname(__FILE__) . '/class.common.dao.fichier.php'; ?> \ No newline at end of file diff --git a/inc/commons/DAO/class.common.dao.fichier.php b/inc/commons/DAO/class.common.dao.fichier.php new file mode 100644 index 000000000..74e7f5f7e --- /dev/null +++ b/inc/commons/DAO/class.common.dao.fichier.php @@ -0,0 +1,146 @@ +contact = $infos['contact']; + $fichier->destinataire = $infos['destinataire']; + $e = explode('/', $path); + $fichier->chemin = $path; + $fichier->nom = array_pop($e); + $e = explode('.', $fichier->nom); + $fichier->type = mb_strtolower(array_pop($e)); + $fichier->taille = filesize($path); + $fichier->date = filemtime($path); + $fichier->relPath = $rel_path; + return $fichier; + } + + public function getListe($orderby = null, $sens = null, $limit = null) + { + $dao = new commonDAOEntreprise($this->con); + $contacts = $dao->getContacts($this->entreprise_id); + $daoEquipiers = new commonDAOEquipier($this->con); + $eq = $daoEquipiers->selectAll(); + $equipiers = array(); + foreach($eq as $e) { + $equipiers[$e->utilisateur_id] = $e; + } + + $paths = array(); + $c = array(); + foreach($contacts as $contact) { + $c[$contact->utilisateur_id] = $contact; + $paths[$contact->utilisateur_id] = array(); + cubeFiles::scanRecursiveDir(FTPROOT . $contact->utilisateur_id, $paths[$contact->utilisateur_id]); + } + + $liste = array(); + foreach($paths as $utilisateur_id => $files) { + foreach($files as $file) { + if (stristr($file, '/.in/')) { + $p = explode('/', str_replace(FTPROOT . $utilisateur_id . '/.in/', '', $file)); + $equipier_id = array_shift($p); + $liste[] = array('path' => $file, 'contact' => $equipiers[$equipier_id], 'destinataire' => $c[$utilisateur_id]); + } else { + $liste[] = array('path' => $file, 'contact' => $c[$utilisateur_id], 'destinataire' => null); + } + } + } + + $fichiers = $this->factory($liste); + $this->orderby = $orderby; + $this->sens = $sens; + if (!is_null($this->q)) { + $limit = null; + $fichiers = $this->search($fichiers); + } + + usort($fichiers, array($this, 'sort')); + + if (!is_null($limit) && $limit) { + $fichiers = array_slice($fichiers, $limit[0], $limit[1]); + } + return $fichiers; + } + + public function count() + { + $dao = new commonDAOEntreprise($this->con); + $contacts = $dao->getContacts($this->entreprise_id); + $res = 0; + foreach($contacts as $contact) { + $t = array(); + cubeFiles::scanRecursiveDir(FTPROOT . $contact->utilisateur_id, $t); + $res += count($t); + } + return $res; + } + + public function sort($a, $b) + { + $a1 = $a-> { + $this->orderby} ; + $b1 = $b-> { + $this->orderby} ; + + if (is_numeric($a1) && is_numeric($b1)) { + if ($a1 == $b1) { + $cmp = 0; + } elseif ($a1 <= $b1) { + $cmp = -1; + } else { + $cmp = 1; + } + } else { + $cmp = strcasecmp($a1, $b1); + } + if ($this->sens == 'ASC') { + return $cmp; + } else { + return $cmp * -1; + } + } + + protected function search($fichiers) + { + $res = array(); + foreach($fichiers as $k => $f) { + if (stristr((string)$f, $this->q)) { + $res[$k] = $f; + } + } + return $res; + } + + public function supprime($path) + { + if (file_exists(FTPROOT . $path)) { + 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/commons/Metier/class.extranet.fichier.php b/inc/commons/Metier/class.extranet.fichier.php new file mode 100644 index 000000000..133c13025 --- /dev/null +++ b/inc/commons/Metier/class.extranet.fichier.php @@ -0,0 +1,25 @@ + $v) { + if (!in_array($k, $skip)) { + $r[] = (string)$v; + } + } + return implode($r); + } +} + +?> \ No newline at end of file diff --git a/inc/commons/class.common.droits.php b/inc/commons/class.common.droits.php index 88a84c959..ede7b00eb 100644 --- a/inc/commons/class.common.droits.php +++ b/inc/commons/class.common.droits.php @@ -1,5 +1,22 @@ user->grade; + }elseif(MODE=='ws'){ + $val=$core->user->ws_grade; + } + if ($val < $grade) { + if (!$error) { + return false; + } + commonDroits::error(); + } + } + public static function recherche($page) { global $core; diff --git a/inc/commons/class.common.url.php b/inc/commons/class.common.url.php index acd1be616..5372ea1d7 100644 --- a/inc/commons/class.common.url.php +++ b/inc/commons/class.common.url.php @@ -289,7 +289,7 @@ class commonUrl { public static function fichiers($args) { global $core; - extranetDroits::min(0); + commonDroits::min(0); $settings = $core->user->getSettings('fichiers'); @@ -365,7 +365,7 @@ class commonUrl { public static function listeFichiers($settings = null) { global $core; - extranetDroits::min(0); + wsDroits::min(0); if ($core->user->grade <= 0) { $entreprise = $core->user->entreprise; } else { @@ -424,7 +424,7 @@ class commonUrl { array_shift($args); $path = implode('/', $args); $utilisateur_id = array_shift($args); - extranetDroits::telecharger($utilisateur_id); + wsDroits::telecharger($utilisateur_id); $dir = md5($path . (rand(1, 235548684) * 50.5)); $nom = array_pop($args); @mkdir(ROOT . '/cache/download/' . $dir, 0755, true); @@ -478,7 +478,7 @@ class commonUrl { if (!$for) { $mail->to = TEAM_EMAIL; $mail->subject = '[' . EMAIL_SUBJECT . '] Nouveaux fichiers uploadés par ' . $core->user->prenom . ' ' . $core->user->nom; - $body = 'Tous les fichiers de ' . $core->user->prenom . ' ' . $core->user->nom . ' : http://extranet.cubedesigners.com/fichiers/' . $core->user->utilisateur_id . "\n\n"; + $body = 'Tous les fichiers de ' . $core->user->prenom . ' ' . $core->user->nom . ' : http://'.$_SERVER['HTTP_HOST'].'/fichiers/' . $core->user->utilisateur_id . "\n\n"; $body .= 'Fichiers chargés : ' . "\n"; foreach($_SESSION['files_uploaded'] as $f) { $body .= ' - http://' . $_SERVER['HTTP_HOST'] . '/telecharger/' . $f . "\n"; @@ -490,7 +490,7 @@ class commonUrl { $mail->to = $core->user->email; $mail->subject = '[' . EMAIL_SUBJECT . '] Nouveaux fichiers uploadés pour ' . $client->prenom . ' ' . $client->nom; - $body = 'Tous les fichiers de ' . $client->prenom . ' ' . $client->nom . ' : http://extranet.cubedesigners.com/fichiers/' . $client->utilisateur_id . "\n\n"; + $body = 'Tous les fichiers de ' . $client->prenom . ' ' . $client->nom . ' : http://'.$_SERVER['HTTP_HOST'].'/fichiers/' . $client->utilisateur_id . "\n\n"; $body .= 'Fichiers chargés : ' . "\n"; foreach($_SESSION['files_uploaded'] as $f) { $body .= ' - http://' . $_SERVER['HTTP_HOST'] . '/telecharger/' . $f . "\n"; @@ -534,6 +534,45 @@ class commonUrl { $dao = new extranetDAOFichier($core->con); $dao->deleteOldFiles(); } + + public static function adresse($utilisateur_id = null, $projet_id = null, $display = 'devis', $adresse = '') + { + global $core; + $dao = new commonDAOClient($core->con); + if (!is_null($utilisateur_id)) { + $client = $dao->selectById($utilisateur_id); + } + if (!is_null($projet_id)) { + $client = $dao->selectByProjet($projet_id); + } + if (is_null($client)) { + return false; + } + + if ($adresse == '') { + $adresse = array(); + fb($client->adresse_facturation); + if ($client->adresse_facturation != '') { + $adresse[] = $client->adresse_facturation; + } else { + $adresse[] = $client->rs; + $adresse[] = trim($client->adresse); + $adresse[] = $client->code_postal . ' ' . $client->ville; + $adresse[] = cubeCountry::getCountry($client->pays); + } + } else { + $adresse = explode("\n", trim($adresse)); + } + if ($display == 'facture' && $client->tva_intra != '' && cubeCountry::inUE($client->pays)) { + $tva = '
' . __('N° de TVA Intracommunautaire') . ' : ' . $client->tva_intra . ''; + } else { + $tva = ''; + } + $a = form::textarea('adresse', 40, 6, implode("\n", $adresse)); + $a .= $tva; + $a .= '' . cubeMedia::image(IMG . '/edit.png') . ''; + return $a; + } } ?> \ No newline at end of file diff --git a/inc/extranet/Controlleur/class.extranet.url.php b/inc/extranet/Controlleur/class.extranet.url.php index 1d93a8c85..caa74076b 100644 --- a/inc/extranet/Controlleur/class.extranet.url.php +++ b/inc/extranet/Controlleur/class.extranet.url.php @@ -1044,45 +1044,6 @@ class extranetUrl { return $res; } - public static function adresse($utilisateur_id = null, $projet_id = null, $display = 'devis', $adresse = '') - { - global $core; - $dao = new commonDAOClient($core->con); - if (!is_null($utilisateur_id)) { - $client = $dao->selectById($utilisateur_id); - } - if (!is_null($projet_id)) { - $client = $dao->selectByProjet($projet_id); - } - if (is_null($client)) { - return false; - } - - if ($adresse == '') { - $adresse = array(); - fb($client->adresse_facturation); - if ($client->adresse_facturation != '') { - $adresse[] = $client->adresse_facturation; - } else { - $adresse[] = $client->rs; - $adresse[] = trim($client->adresse); - $adresse[] = $client->code_postal . ' ' . $client->ville; - $adresse[] = cubeCountry::getCountry($client->pays); - } - } else { - $adresse = explode("\n", trim($adresse)); - } - if ($display == 'facture' && $client->tva_intra != '' && cubeCountry::inUE($client->pays)) { - $tva = '
' . __('N° de TVA Intracommunautaire') . ' : ' . $client->tva_intra . ''; - } else { - $tva = ''; - } - $a = form::textarea('adresse', 40, 6, implode("\n", $adresse)); - $a .= $tva; - $a .= '' . cubeMedia::image(IMG . '/edit.png') . ''; - return $a; - } - public static function previewDevis($args) { global $core; diff --git a/inc/extranet/DAO/class.extranet.dao.fichier.php b/inc/extranet/DAO/class.extranet.dao.fichier.php deleted file mode 100644 index e494baa1d..000000000 --- a/inc/extranet/DAO/class.extranet.dao.fichier.php +++ /dev/null @@ -1,146 +0,0 @@ -contact = $infos['contact']; - $fichier->destinataire = $infos['destinataire']; - $e = explode('/', $path); - $fichier->chemin = $path; - $fichier->nom = array_pop($e); - $e = explode('.', $fichier->nom); - $fichier->type = mb_strtolower(array_pop($e)); - $fichier->taille = filesize($path); - $fichier->date = filemtime($path); - $fichier->relPath = $rel_path; - return $fichier; - } - - public function getListe($orderby = null, $sens = null, $limit = null) - { - $dao = new commonDAOEntreprise($this->con); - $contacts = $dao->getContacts($this->entreprise_id); - $daoEquipiers = new commonDAOEquipier($this->con); - $eq = $daoEquipiers->selectAll(); - $equipiers = array(); - foreach($eq as $e) { - $equipiers[$e->utilisateur_id] = $e; - } - - $paths = array(); - $c = array(); - foreach($contacts as $contact) { - $c[$contact->utilisateur_id] = $contact; - $paths[$contact->utilisateur_id] = array(); - cubeFiles::scanRecursiveDir(FTPROOT . $contact->utilisateur_id, $paths[$contact->utilisateur_id]); - } - - $liste = array(); - foreach($paths as $utilisateur_id => $files) { - foreach($files as $file) { - if (stristr($file, '/.in/')) { - $p = explode('/', str_replace(FTPROOT . $utilisateur_id . '/.in/', '', $file)); - $equipier_id = array_shift($p); - $liste[] = array('path' => $file, 'contact' => $equipiers[$equipier_id], 'destinataire' => $c[$utilisateur_id]); - } else { - $liste[] = array('path' => $file, 'contact' => $c[$utilisateur_id], 'destinataire' => null); - } - } - } - - $fichiers = $this->factory($liste); - $this->orderby = $orderby; - $this->sens = $sens; - if (!is_null($this->q)) { - $limit = null; - $fichiers = $this->search($fichiers); - } - - usort($fichiers, array($this, 'sort')); - - if (!is_null($limit) && $limit) { - $fichiers = array_slice($fichiers, $limit[0], $limit[1]); - } - return $fichiers; - } - - public function count() - { - $dao = new commonDAOEntreprise($this->con); - $contacts = $dao->getContacts($this->entreprise_id); - $res = 0; - foreach($contacts as $contact) { - $t = array(); - cubeFiles::scanRecursiveDir(FTPROOT . $contact->utilisateur_id, $t); - $res += count($t); - } - return $res; - } - - public function sort($a, $b) - { - $a1 = $a-> { - $this->orderby} ; - $b1 = $b-> { - $this->orderby} ; - - if (is_numeric($a1) && is_numeric($b1)) { - if ($a1 == $b1) { - $cmp = 0; - } elseif ($a1 <= $b1) { - $cmp = -1; - } else { - $cmp = 1; - } - } else { - $cmp = strcasecmp($a1, $b1); - } - if ($this->sens == 'ASC') { - return $cmp; - } else { - return $cmp * -1; - } - } - - protected function search($fichiers) - { - $res = array(); - foreach($fichiers as $k => $f) { - if (stristr((string)$f, $this->q)) { - $res[$k] = $f; - } - } - return $res; - } - - public function supprime($path) - { - if (file_exists(FTPROOT . $path)) { - 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/Metier/class.extranet.fichier.php b/inc/extranet/Metier/class.extranet.fichier.php deleted file mode 100644 index 133c13025..000000000 --- a/inc/extranet/Metier/class.extranet.fichier.php +++ /dev/null @@ -1,25 +0,0 @@ - $v) { - if (!in_array($k, $skip)) { - $r[] = (string)$v; - } - } - return implode($r); - } -} - -?> \ No newline at end of file diff --git a/inc/ws/Controlleur/class.ws.ajax.php b/inc/ws/Controlleur/class.ws.ajax.php index 7040ca7d0..6e3a1dabf 100644 --- a/inc/ws/Controlleur/class.ws.ajax.php +++ b/inc/ws/Controlleur/class.ws.ajax.php @@ -1,6 +1,114 @@


' . wsUrl::listeContacts($args[1]) . '
'; + } + $extra .= '



' . $core->typo->BoutonOK(__('Enregistrer')) . '

'; + + commonAjax::form('saveClient', __("Edition d'un client"), wsUrl::formClient($args[1]), false, 2, '', $extra); + } + + public static function formContact($args, &$x) + { + if (!isset($args[2])) { + $args[2] = null; + } + commonAjax::form('saveContact', __("Edition d'un contact"), wsUrl::formContact($args[1], $args[2])); + } + + public static function saveClient($args, &$x) + { + global $core; + $dao = new commonDAOEntreprise($core->con); + $entreprise = $dao->sauve($_POST); + if ($_POST['entreprise_id'] == 'new') { + $data = $_POST['contact']; + $data['entreprise'] = $entreprise->entreprise_id; + $data['utilisateur_id'] = 'new'; + $data['adresse'] = $entreprise->adresse; + $data['code_postal'] = $entreprise->code_postal; + $data['ville'] = $entreprise->ville; + $data['pays'] = $entreprise->pays; + $data['grade'] = 0; + $data['adresse_facturation'] = $entreprise->adresse_facturation; + $daoClient = new commonDAOClient($core->con); + try { + $daoClient->sauve($data); + } + catch(exception $e) { + $dao->supprime($entreprise->entreprise_id); + } + } + + $x->addContent('listeClients', wsUrl::listeClients()); + $x->addClosePopup(); + } + + public static function saveNotes($args, &$x) + { + global $core; + $dao = new commonDAOClient($core->con); + $dao->sauveNotes($_POST['utilisateur_id'], $_POST['notes']); + $x->addClosePopup(); + } + + public static function saveContact($args, &$x) + { + global $core; + $dao = new commonDAOClient($core->con); + $client = $dao->sauve($_POST); + $x->addClosePopup(); + $x->addContent('devisAdresseDisplay', wsUrl::adresse($client->utilisateur_id, null, 'devis')); + $x->addContent('factureAdresseDisplay', wsUrl::adresse($client->utilisateur_id, null, 'facture')); + $x->addContent('listeContacts', wsUrl::listeContacts($client->entreprise)); + $contacts = array(); + $client_contacts = $dao->getContactsOfEntreprise($client->entreprise); + foreach($client_contacts as $c) { + $contacts[] = '' . $c->prenom . ' ' . $c->nom . ''; + } + $x->addContent('contacts_' . $client->entreprise, implode(', ', $contacts)); + + $x->addPopupDimensions(); + } + + public static function supprimeClient($args, &$x) + { + global $core; + $dao = new commonDAOEntreprise($core->con); + $dao->supprime($args[1]); + + $x->addContent('listeClients', wsUrl::listeClients()); + } + + public static function searchClients($args, &$x) + { + $x->addContent('listeClients', wsUrl::listeClients()); + } + + public static function sortClient($args, &$x) + { + commonAjax::sort('clients', $args[1]); + $x->addContent('listeClients', wsUrl::listeClients()); + } + + public static function pageClient($args, &$x) + { + commonAjax::page('clients', $args[1]); + $x->addContent('listeClients', wsUrl::listeClients()); + } + + public static function parPageClient($args, &$x) + { + commonAjax::parPage('clients', $_POST['par_page']); + $x->addContent('listeClients', wsUrl::listeClients()); + } + public static function supprimeBook($args, &$x) { global $core;