$__autoload['commonDAOEquipier'] = dirname(__FILE__) . '/class.common.dao.equipier.php';\r
$__autoload['commonDAOClient'] = dirname(__FILE__) . '/class.common.dao.client.php';\r
$__autoload['commonDAOEntreprise'] = dirname(__FILE__) . '/class.common.dao.entreprise.php';\r
+$__autoload['commonDAOFichier'] = dirname(__FILE__) . '/class.common.dao.fichier.php';\r
\r
?>
\ No newline at end of file
--- /dev/null
+<?php\r
+class commonDAOFichier extends commonDAO {\r
+ public $entreprise_id;\r
+ public function singleton($infos)\r
+ {\r
+ $path = path::real($infos['path']);\r
+ $rel_path = str_replace(FTPROOT, '', $path);\r
+ $fichier = new extranetFichier();\r
+ $fichier->contact = $infos['contact'];\r
+ $fichier->destinataire = $infos['destinataire'];\r
+ $e = explode('/', $path);\r
+ $fichier->chemin = $path;\r
+ $fichier->nom = array_pop($e);\r
+ $e = explode('.', $fichier->nom);\r
+ $fichier->type = mb_strtolower(array_pop($e));\r
+ $fichier->taille = filesize($path);\r
+ $fichier->date = filemtime($path);\r
+ $fichier->relPath = $rel_path;\r
+ return $fichier;\r
+ }\r
+\r
+ public function getListe($orderby = null, $sens = null, $limit = null)\r
+ {\r
+ $dao = new commonDAOEntreprise($this->con);\r
+ $contacts = $dao->getContacts($this->entreprise_id);\r
+ $daoEquipiers = new commonDAOEquipier($this->con);\r
+ $eq = $daoEquipiers->selectAll();\r
+ $equipiers = array();\r
+ foreach($eq as $e) {\r
+ $equipiers[$e->utilisateur_id] = $e;\r
+ }\r
+\r
+ $paths = array();\r
+ $c = array();\r
+ foreach($contacts as $contact) {\r
+ $c[$contact->utilisateur_id] = $contact;\r
+ $paths[$contact->utilisateur_id] = array();\r
+ cubeFiles::scanRecursiveDir(FTPROOT . $contact->utilisateur_id, $paths[$contact->utilisateur_id]);\r
+ }\r
+\r
+ $liste = array();\r
+ foreach($paths as $utilisateur_id => $files) {\r
+ foreach($files as $file) {\r
+ if (stristr($file, '/.in/')) {\r
+ $p = explode('/', str_replace(FTPROOT . $utilisateur_id . '/.in/', '', $file));\r
+ $equipier_id = array_shift($p);\r
+ $liste[] = array('path' => $file, 'contact' => $equipiers[$equipier_id], 'destinataire' => $c[$utilisateur_id]);\r
+ } else {\r
+ $liste[] = array('path' => $file, 'contact' => $c[$utilisateur_id], 'destinataire' => null);\r
+ }\r
+ }\r
+ }\r
+\r
+ $fichiers = $this->factory($liste);\r
+ $this->orderby = $orderby;\r
+ $this->sens = $sens;\r
+ if (!is_null($this->q)) {\r
+ $limit = null;\r
+ $fichiers = $this->search($fichiers);\r
+ }\r
+\r
+ usort($fichiers, array($this, 'sort'));\r
+\r
+ if (!is_null($limit) && $limit) {\r
+ $fichiers = array_slice($fichiers, $limit[0], $limit[1]);\r
+ }\r
+ return $fichiers;\r
+ }\r
+\r
+ public function count()\r
+ {\r
+ $dao = new commonDAOEntreprise($this->con);\r
+ $contacts = $dao->getContacts($this->entreprise_id);\r
+ $res = 0;\r
+ foreach($contacts as $contact) {\r
+ $t = array();\r
+ cubeFiles::scanRecursiveDir(FTPROOT . $contact->utilisateur_id, $t);\r
+ $res += count($t);\r
+ }\r
+ return $res;\r
+ }\r
+\r
+ public function sort($a, $b)\r
+ {\r
+ $a1 = $a-> {\r
+ $this->orderby} ;\r
+ $b1 = $b-> {\r
+ $this->orderby} ;\r
+\r
+ if (is_numeric($a1) && is_numeric($b1)) {\r
+ if ($a1 == $b1) {\r
+ $cmp = 0;\r
+ } elseif ($a1 <= $b1) {\r
+ $cmp = -1;\r
+ } else {\r
+ $cmp = 1;\r
+ }\r
+ } else {\r
+ $cmp = strcasecmp($a1, $b1);\r
+ }\r
+ if ($this->sens == 'ASC') {\r
+ return $cmp;\r
+ } else {\r
+ return $cmp * -1;\r
+ }\r
+ }\r
+\r
+ protected function search($fichiers)\r
+ {\r
+ $res = array();\r
+ foreach($fichiers as $k => $f) {\r
+ if (stristr((string)$f, $this->q)) {\r
+ $res[$k] = $f;\r
+ }\r
+ }\r
+ return $res;\r
+ }\r
+\r
+ public function supprime($path)\r
+ {\r
+ if (file_exists(FTPROOT . $path)) {\r
+ unlink(FTPROOT . $path);\r
+ }\r
+ }\r
+\r
+ public function deleteOldFiles()\r
+ {\r
+ $root = FTPROOT;\r
+ cubeFiles::scanRecursiveDir($root, $files);\r
+\r
+ $limit = TIME-3600 * 24 * 60; // 60 days\r
+\r
+ $size = 0;\r
+\r
+ foreach($files as $f) {\r
+ if (filemtime($f) < $limit) {\r
+ fb(date('Y-m-d', filemtime($f)), $f);\r
+ $size += filesize($f);\r
+ unlink($f);\r
+ }\r
+ }\r
+ fb(files::size($size), 'Size of files deleted');\r
+ }\r
+}\r
+\r
+?>
\ No newline at end of file
--- /dev/null
+<?php\r
+class extranetFichier extends cubeMetier {\r
+ protected $nom;\r
+ protected $type;\r
+ protected $taille;\r
+ protected $date;\r
+ protected $chemin;\r
+ protected $contact;\r
+ protected $destinataire;\r
+ protected $relPath;\r
+\r
+ public function __toString()\r
+ {\r
+ $r = array();\r
+ $skip = array('taille', 'date', 'chemin', 'type','relPath');\r
+ foreach($this as $k => $v) {\r
+ if (!in_array($k, $skip)) {\r
+ $r[] = (string)$v;\r
+ }\r
+ }\r
+ return implode($r);\r
+ }\r
+}\r
+\r
+?>
\ No newline at end of file
<?php\r
class commonDroits {\r
+\r
+ public static function min($grade, $error = true)\r
+ {\r
+ global $core;\r
+ if(MODE=='extranet'){\r
+ $val=$core->user->grade;\r
+ }elseif(MODE=='ws'){\r
+ $val=$core->user->ws_grade;\r
+ }\r
+ if ($val < $grade) {\r
+ if (!$error) {\r
+ return false;\r
+ }\r
+ commonDroits::error();\r
+ }\r
+ }\r
+\r
public static function recherche($page)\r
{\r
global $core;\r
public static function fichiers($args)\r
{\r
global $core;\r
- extranetDroits::min(0);\r
+ commonDroits::min(0);\r
\r
$settings = $core->user->getSettings('fichiers');\r
\r
public static function listeFichiers($settings = null)\r
{\r
global $core;\r
- extranetDroits::min(0);\r
+ wsDroits::min(0);\r
if ($core->user->grade <= 0) {\r
$entreprise = $core->user->entreprise;\r
} else {\r
array_shift($args);\r
$path = implode('/', $args);\r
$utilisateur_id = array_shift($args);\r
- extranetDroits::telecharger($utilisateur_id);\r
+ wsDroits::telecharger($utilisateur_id);\r
$dir = md5($path . (rand(1, 235548684) * 50.5));\r
$nom = array_pop($args);\r
@mkdir(ROOT . '/cache/download/' . $dir, 0755, true);\r
if (!$for) {\r
$mail->to = TEAM_EMAIL;\r
$mail->subject = '[' . EMAIL_SUBJECT . '] Nouveaux fichiers uploadés par ' . $core->user->prenom . ' ' . $core->user->nom;\r
- $body = 'Tous les fichiers de ' . $core->user->prenom . ' ' . $core->user->nom . ' : http://extranet.cubedesigners.com/fichiers/' . $core->user->utilisateur_id . "\n\n";\r
+ $body = 'Tous les fichiers de ' . $core->user->prenom . ' ' . $core->user->nom . ' : http://'.$_SERVER['HTTP_HOST'].'/fichiers/' . $core->user->utilisateur_id . "\n\n";\r
$body .= 'Fichiers chargés : ' . "\n";\r
foreach($_SESSION['files_uploaded'] as $f) {\r
$body .= ' - http://' . $_SERVER['HTTP_HOST'] . '/telecharger/' . $f . "\n";\r
$mail->to = $core->user->email;\r
$mail->subject = '[' . EMAIL_SUBJECT . '] Nouveaux fichiers uploadés pour ' . $client->prenom . ' ' . $client->nom;\r
\r
- $body = 'Tous les fichiers de ' . $client->prenom . ' ' . $client->nom . ' : http://extranet.cubedesigners.com/fichiers/' . $client->utilisateur_id . "\n\n";\r
+ $body = 'Tous les fichiers de ' . $client->prenom . ' ' . $client->nom . ' : http://'.$_SERVER['HTTP_HOST'].'/fichiers/' . $client->utilisateur_id . "\n\n";\r
$body .= 'Fichiers chargés : ' . "\n";\r
foreach($_SESSION['files_uploaded'] as $f) {\r
$body .= ' - http://' . $_SERVER['HTTP_HOST'] . '/telecharger/' . $f . "\n";\r
$dao = new extranetDAOFichier($core->con);\r
$dao->deleteOldFiles();\r
}\r
+\r
+ public static function adresse($utilisateur_id = null, $projet_id = null, $display = 'devis', $adresse = '')\r
+ {\r
+ global $core;\r
+ $dao = new commonDAOClient($core->con);\r
+ if (!is_null($utilisateur_id)) {\r
+ $client = $dao->selectById($utilisateur_id);\r
+ }\r
+ if (!is_null($projet_id)) {\r
+ $client = $dao->selectByProjet($projet_id);\r
+ }\r
+ if (is_null($client)) {\r
+ return false;\r
+ }\r
+\r
+ if ($adresse == '') {\r
+ $adresse = array();\r
+ fb($client->adresse_facturation);\r
+ if ($client->adresse_facturation != '') {\r
+ $adresse[] = $client->adresse_facturation;\r
+ } else {\r
+ $adresse[] = $client->rs;\r
+ $adresse[] = trim($client->adresse);\r
+ $adresse[] = $client->code_postal . ' ' . $client->ville;\r
+ $adresse[] = cubeCountry::getCountry($client->pays);\r
+ }\r
+ } else {\r
+ $adresse = explode("\n", trim($adresse));\r
+ }\r
+ if ($display == 'facture' && $client->tva_intra != '' && cubeCountry::inUE($client->pays)) {\r
+ $tva = '<br /><span class="tva">' . __('N° de TVA Intracommunautaire') . ' : ' . $client->tva_intra . '</span>';\r
+ } else {\r
+ $tva = '';\r
+ }\r
+ $a = form::textarea('adresse', 40, 6, implode("\n", $adresse));\r
+ $a .= $tva;\r
+ $a .= '<a href="#" class="popup edit" rel="formContact/' . $client->utilisateur_id . '" title="' . __('Editer les informations de ce client') . '">' . cubeMedia::image(IMG . '/edit.png') . '</a>';\r
+ return $a;\r
+ }\r
}\r
\r
?>
\ No newline at end of file
return $res;\r
}\r
\r
- public static function adresse($utilisateur_id = null, $projet_id = null, $display = 'devis', $adresse = '')\r
- {\r
- global $core;\r
- $dao = new commonDAOClient($core->con);\r
- if (!is_null($utilisateur_id)) {\r
- $client = $dao->selectById($utilisateur_id);\r
- }\r
- if (!is_null($projet_id)) {\r
- $client = $dao->selectByProjet($projet_id);\r
- }\r
- if (is_null($client)) {\r
- return false;\r
- }\r
-\r
- if ($adresse == '') {\r
- $adresse = array();\r
- fb($client->adresse_facturation);\r
- if ($client->adresse_facturation != '') {\r
- $adresse[] = $client->adresse_facturation;\r
- } else {\r
- $adresse[] = $client->rs;\r
- $adresse[] = trim($client->adresse);\r
- $adresse[] = $client->code_postal . ' ' . $client->ville;\r
- $adresse[] = cubeCountry::getCountry($client->pays);\r
- }\r
- } else {\r
- $adresse = explode("\n", trim($adresse));\r
- }\r
- if ($display == 'facture' && $client->tva_intra != '' && cubeCountry::inUE($client->pays)) {\r
- $tva = '<br /><span class="tva">' . __('N° de TVA Intracommunautaire') . ' : ' . $client->tva_intra . '</span>';\r
- } else {\r
- $tva = '';\r
- }\r
- $a = form::textarea('adresse', 40, 6, implode("\n", $adresse));\r
- $a .= $tva;\r
- $a .= '<a href="#" class="popup edit" rel="formContact/' . $client->utilisateur_id . '" title="' . __('Editer les informations de ce client') . '">' . cubeMedia::image(IMG . '/edit.png') . '</a>';\r
- return $a;\r
- }\r
-\r
public static function previewDevis($args)\r
{\r
global $core;\r
+++ /dev/null
-<?php\r
-class extranetDAOFichier extends commonDAO {\r
- public $entreprise_id;\r
- public function singleton($infos)\r
- {\r
- $path = path::real($infos['path']);\r
- $rel_path = str_replace(FTPROOT, '', $path);\r
- $fichier = new extranetFichier();\r
- $fichier->contact = $infos['contact'];\r
- $fichier->destinataire = $infos['destinataire'];\r
- $e = explode('/', $path);\r
- $fichier->chemin = $path;\r
- $fichier->nom = array_pop($e);\r
- $e = explode('.', $fichier->nom);\r
- $fichier->type = mb_strtolower(array_pop($e));\r
- $fichier->taille = filesize($path);\r
- $fichier->date = filemtime($path);\r
- $fichier->relPath = $rel_path;\r
- return $fichier;\r
- }\r
-\r
- public function getListe($orderby = null, $sens = null, $limit = null)\r
- {\r
- $dao = new commonDAOEntreprise($this->con);\r
- $contacts = $dao->getContacts($this->entreprise_id);\r
- $daoEquipiers = new commonDAOEquipier($this->con);\r
- $eq = $daoEquipiers->selectAll();\r
- $equipiers = array();\r
- foreach($eq as $e) {\r
- $equipiers[$e->utilisateur_id] = $e;\r
- }\r
-\r
- $paths = array();\r
- $c = array();\r
- foreach($contacts as $contact) {\r
- $c[$contact->utilisateur_id] = $contact;\r
- $paths[$contact->utilisateur_id] = array();\r
- cubeFiles::scanRecursiveDir(FTPROOT . $contact->utilisateur_id, $paths[$contact->utilisateur_id]);\r
- }\r
-\r
- $liste = array();\r
- foreach($paths as $utilisateur_id => $files) {\r
- foreach($files as $file) {\r
- if (stristr($file, '/.in/')) {\r
- $p = explode('/', str_replace(FTPROOT . $utilisateur_id . '/.in/', '', $file));\r
- $equipier_id = array_shift($p);\r
- $liste[] = array('path' => $file, 'contact' => $equipiers[$equipier_id], 'destinataire' => $c[$utilisateur_id]);\r
- } else {\r
- $liste[] = array('path' => $file, 'contact' => $c[$utilisateur_id], 'destinataire' => null);\r
- }\r
- }\r
- }\r
-\r
- $fichiers = $this->factory($liste);\r
- $this->orderby = $orderby;\r
- $this->sens = $sens;\r
- if (!is_null($this->q)) {\r
- $limit = null;\r
- $fichiers = $this->search($fichiers);\r
- }\r
-\r
- usort($fichiers, array($this, 'sort'));\r
-\r
- if (!is_null($limit) && $limit) {\r
- $fichiers = array_slice($fichiers, $limit[0], $limit[1]);\r
- }\r
- return $fichiers;\r
- }\r
-\r
- public function count()\r
- {\r
- $dao = new commonDAOEntreprise($this->con);\r
- $contacts = $dao->getContacts($this->entreprise_id);\r
- $res = 0;\r
- foreach($contacts as $contact) {\r
- $t = array();\r
- cubeFiles::scanRecursiveDir(FTPROOT . $contact->utilisateur_id, $t);\r
- $res += count($t);\r
- }\r
- return $res;\r
- }\r
-\r
- public function sort($a, $b)\r
- {\r
- $a1 = $a-> {\r
- $this->orderby} ;\r
- $b1 = $b-> {\r
- $this->orderby} ;\r
-\r
- if (is_numeric($a1) && is_numeric($b1)) {\r
- if ($a1 == $b1) {\r
- $cmp = 0;\r
- } elseif ($a1 <= $b1) {\r
- $cmp = -1;\r
- } else {\r
- $cmp = 1;\r
- }\r
- } else {\r
- $cmp = strcasecmp($a1, $b1);\r
- }\r
- if ($this->sens == 'ASC') {\r
- return $cmp;\r
- } else {\r
- return $cmp * -1;\r
- }\r
- }\r
-\r
- protected function search($fichiers)\r
- {\r
- $res = array();\r
- foreach($fichiers as $k => $f) {\r
- if (stristr((string)$f, $this->q)) {\r
- $res[$k] = $f;\r
- }\r
- }\r
- return $res;\r
- }\r
-\r
- public function supprime($path)\r
- {\r
- if (file_exists(FTPROOT . $path)) {\r
- unlink(FTPROOT . $path);\r
- }\r
- }\r
-\r
- public function deleteOldFiles()\r
- {\r
- $root = FTPROOT;\r
- cubeFiles::scanRecursiveDir($root, $files);\r
-\r
- $limit = TIME-3600 * 24 * 60; // 60 days\r
-\r
- $size = 0;\r
-\r
- foreach($files as $f) {\r
- if (filemtime($f) < $limit) {\r
- fb(date('Y-m-d', filemtime($f)), $f);\r
- $size += filesize($f);\r
- unlink($f);\r
- }\r
- }\r
- fb(files::size($size), 'Size of files deleted');\r
- }\r
-}\r
-\r
-?>
\ No newline at end of file
+++ /dev/null
-<?php\r
-class extranetFichier extends cubeMetier {\r
- protected $nom;\r
- protected $type;\r
- protected $taille;\r
- protected $date;\r
- protected $chemin;\r
- protected $contact;\r
- protected $destinataire;\r
- protected $relPath;\r
-\r
- public function __toString()\r
- {\r
- $r = array();\r
- $skip = array('taille', 'date', 'chemin', 'type','relPath');\r
- foreach($this as $k => $v) {\r
- if (!in_array($k, $skip)) {\r
- $r[] = (string)$v;\r
- }\r
- }\r
- return implode($r);\r
- }\r
-}\r
-\r
-?>
\ No newline at end of file
<?php\r
\r
class wsAjax extends cubeAjax {\r
+ public static function formClient($args, &$x)\r
+ {\r
+ global $core;\r
+ if ($args[1] == 'new') {\r
+ $extra = '';\r
+ } else {\r
+ $extra = '<p><br /><br /><br /></p><div id="listeContacts">' . wsUrl::listeContacts($args[1]) . '</div>';\r
+ }\r
+ $extra .= '<p class="right" style="margin-top:10px;margin-right:10px;"><br /><br /><a href="#" class="submit">' . $core->typo->BoutonOK(__('Enregistrer')) . '</a><br /><br /></p>';\r
+\r
+ commonAjax::form('saveClient', __("Edition d'un client"), wsUrl::formClient($args[1]), false, 2, '', $extra);\r
+ }\r
+\r
+ public static function formContact($args, &$x)\r
+ {\r
+ if (!isset($args[2])) {\r
+ $args[2] = null;\r
+ }\r
+ commonAjax::form('saveContact', __("Edition d'un contact"), wsUrl::formContact($args[1], $args[2]));\r
+ }\r
+\r
+ public static function saveClient($args, &$x)\r
+ {\r
+ global $core;\r
+ $dao = new commonDAOEntreprise($core->con);\r
+ $entreprise = $dao->sauve($_POST);\r
+ if ($_POST['entreprise_id'] == 'new') {\r
+ $data = $_POST['contact'];\r
+ $data['entreprise'] = $entreprise->entreprise_id;\r
+ $data['utilisateur_id'] = 'new';\r
+ $data['adresse'] = $entreprise->adresse;\r
+ $data['code_postal'] = $entreprise->code_postal;\r
+ $data['ville'] = $entreprise->ville;\r
+ $data['pays'] = $entreprise->pays;\r
+ $data['grade'] = 0;\r
+ $data['adresse_facturation'] = $entreprise->adresse_facturation;\r
+ $daoClient = new commonDAOClient($core->con);\r
+ try {\r
+ $daoClient->sauve($data);\r
+ }\r
+ catch(exception $e) {\r
+ $dao->supprime($entreprise->entreprise_id);\r
+ }\r
+ }\r
+\r
+ $x->addContent('listeClients', wsUrl::listeClients());\r
+ $x->addClosePopup();\r
+ }\r
+\r
+ public static function saveNotes($args, &$x)\r
+ {\r
+ global $core;\r
+ $dao = new commonDAOClient($core->con);\r
+ $dao->sauveNotes($_POST['utilisateur_id'], $_POST['notes']);\r
+ $x->addClosePopup();\r
+ }\r
+\r
+ public static function saveContact($args, &$x)\r
+ {\r
+ global $core;\r
+ $dao = new commonDAOClient($core->con);\r
+ $client = $dao->sauve($_POST);\r
+ $x->addClosePopup();\r
+ $x->addContent('devisAdresseDisplay', wsUrl::adresse($client->utilisateur_id, null, 'devis'));\r
+ $x->addContent('factureAdresseDisplay', wsUrl::adresse($client->utilisateur_id, null, 'facture'));\r
+ $x->addContent('listeContacts', wsUrl::listeContacts($client->entreprise));\r
+ $contacts = array();\r
+ $client_contacts = $dao->getContactsOfEntreprise($client->entreprise);\r
+ foreach($client_contacts as $c) {\r
+ $contacts[] = '<a href="#" class="popup" rel="formContact/' . $c->utilisateur_id . '">' . $c->prenom . ' ' . $c->nom . '</a>';\r
+ }\r
+ $x->addContent('contacts_' . $client->entreprise, implode(', ', $contacts));\r
+\r
+ $x->addPopupDimensions();\r
+ }\r
+\r
+ public static function supprimeClient($args, &$x)\r
+ {\r
+ global $core;\r
+ $dao = new commonDAOEntreprise($core->con);\r
+ $dao->supprime($args[1]);\r
+\r
+ $x->addContent('listeClients', wsUrl::listeClients());\r
+ }\r
+\r
+ public static function searchClients($args, &$x)\r
+ {\r
+ $x->addContent('listeClients', wsUrl::listeClients());\r
+ }\r
+\r
+ public static function sortClient($args, &$x)\r
+ {\r
+ commonAjax::sort('clients', $args[1]);\r
+ $x->addContent('listeClients', wsUrl::listeClients());\r
+ }\r
+\r
+ public static function pageClient($args, &$x)\r
+ {\r
+ commonAjax::page('clients', $args[1]);\r
+ $x->addContent('listeClients', wsUrl::listeClients());\r
+ }\r
+\r
+ public static function parPageClient($args, &$x)\r
+ {\r
+ commonAjax::parPage('clients', $_POST['par_page']);\r
+ $x->addContent('listeClients', wsUrl::listeClients());\r
+ }\r
+\r
public static function supprimeBook($args, &$x)\r
{\r
global $core;\r