class wsAjax extends cubeAjax
{
- public static function formClient($args, &$x)
- {
- global $core;
- if ($args[1] == 'new') {
- $extra = '';
- } else {
- $extra = '<p><br /><br /><br /></p><div id="listeContacts">' . wsUrl::listeContacts($args[1]) . '</div>';
- }
- $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>';
-
- 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);
- // Creation de l'entreprise
- if ($_POST['entreprise_id'] == 'new') {
- if (!isset($_POST['ws_admin']) || !$_POST['ws_admin']) {
- $_POST['ws_admin'] = $core->user->utilisateur_id;
- $_POST['ws_grade'] = 1;
- }
- }
- if (isset($_POST['ws_admin']) && !$_POST['ws_admin']) {
- $_POST['ws_admin'] = $core->user->utilisateur_id;
- }
- $entreprise = $dao->sauve($_POST);
- // Si c'est une nouvelle entreprise, on crée également le contact
- 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['site'] = $entreprise->site;
- $data['grade'] = 0;
- $daoClient = new commonDAOClient($core->con);
- try {
- $daoClient->sauve($data);
- } catch (exception $e) {
- $dao->supprime($entreprise->entreprise_id);
- }
- }
-
- $core->refreshWSUsersTree();
-
- $x->addContent('listeClients', wsUrl::listeClients());
- $x->addClosePopup();
- }
-
- public static function saveContact($args, &$x)
- {
- global $core;
- $dao = new commonDAOClient($core->con);
- $client = $dao->sauve($_POST);
- $x->addClosePopup();
- $x->addContent('devisAdresseDisplay', commonUrl::adresse($client->utilisateur_id, null, 'devis'));
- $x->addContent('factureAdresseDisplay', commonUrl::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[] = '<a href="#" class="popup" rel="formContact/' . $c->utilisateur_id . '">' . $c->prenom . ' ' . $c->nom . '</a>';
- }
-
- $core->refreshWSUsersTree();
- $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]);
-
- $core->refreshWSUsersTree();
-
- $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_ws', $args[1]);
- $x->addContent('listeClients', wsUrl::listeClients());
- }
-
- public static function sortCollections($args, &$x)
- {
- commonAjax::sort('collections', $args[1]);
- $x->addContent('listeCollections', wsUrl::listeCollections());
- }
-
- public static function pageClient($args, &$x)
- {
- commonAjax::page('clients_ws', $args[1]);
- $x->addContent('listeClients', wsUrl::listeClients());
- }
-
- public static function parPageClient($args, &$x)
- {
- commonAjax::parPage('clients_ws', $_POST['par_page']);
- $x->addContent('listeClients', wsUrl::listeClients());
- }
-
- public static function filtreClients($args, &$x)
- {
- if (isset($args[1]) && $args[1] == 'efface') {
- commonAjax::filtre('clients_ws');
- $x->addReload();
- return;
- } else {
- commonAjax::filtre('clients_ws', $_POST);
- $x->addContent('listeClients', wsUrl::listeClients());
- }
- }
-
- public static function supprimeBook($args, &$x)
- {
- global $core;
- $dao = new wsDAOBook($core->con);
- $dao->supprime($args[1]);
- $x->addContent('listeBooks', wsUrl::listeBooks());
- }
-
- public static function searchPublications($args, &$x)
- {
- $x->addContent('listeBooks', wsUrl::listeBooks());
- }
-
- public static function pageBooks($args, &$x)
- {
- commonAjax::page('books', $args[1]);
- $x->addContent('listeBooks', wsUrl::listeBooks());
- }
-
- public static function parPageBooks($args, &$x)
- {
- commonAjax::parPage('books', $_POST['par_page']);
- $x->addContent('listeBooks', wsUrl::listeBooks());
- }
-
- public static function sortBooks($args, &$x)
- {
- commonAjax::sort('books', $args[1]);
- $x->addContent('listeBooks', wsUrl::listeBooks());
- }
-
- public static function newBookForm($args, &$x)
- {
- commonAjax::form('newBook', __("Créer une nouvelle publication à partir d'une existante"), wsUrl::chooseExistingBook(), __('Créer une nouvelle publication'), 3);
- }
-
- public static function newCollectionForm($args, &$x)
- {
- commonAjax::form('saveCollection', __("Créer une nouvelle collection"), wsUrl::formCollection(), __('Créer une nouvelle collection'), 3);
- }
-
- public static function formChangeBookProprietaire($args, &$x)
- {
- commonAjax::form('changeBookProprietaire/' . $args[1], __("Modifier le propriétaire de la publication"), wsUrl::changeBookProprietaire($args[1]), __('Enregistrer'), 3);
- }
-
- public static function formChangeCollectionProprietaire($args, &$x)
- {
- commonAjax::form('changeCollectionProprietaire/' . $args[1], __("Modifier le propriétaire de la collection"), wsUrl::changeCollectionProprietaire($args[1]), __('Enregistrer'), 3);
- }
-
- public static function filtreBooks($args, &$x)
- {
- if (isset($args[1]) && $args[1] == 'efface') {
- commonAjax::filtre('books');
- $x->addReload();
- return;
- } else {
- commonAjax::filtre('books', $_POST);
- $x->addContent('listeBooks', wsUrl::listeBooks());
- }
- }
-
- public static function newBook($args, &$x)
- {
- global $core;
- $dao = new wsDAOBook($core->con);
- if ($_POST['book'] != '') {
- $book = $dao->duplicate($_POST['book'], $core->user->utilisateur_id, $_POST['title'], isset($_POST['pages']));
- } else {
- $book = $dao->creeEmpty($core->user->utilisateur_id, $core->user->lang, $_POST['title']);
- }
-
- $x->addClosePopup();
- $x->addContent('listeBooks', wsUrl::listeBooks());
- $x->addTruePopup(SITE_PATH . 'editor/' . $book->book_id);
- }
-
- public static function saveCollection($args, &$x)
- {
- global $core;
- $dao = new wsDAOCollection($core->con);
- $dao->sauve($_POST, $core->user->utilisateur_id);
-
- $x->addClosePopup();
- $x->addContent('listeCollections', wsUrl::listeCollections());
- }
-
- public static function saveCollectionComposition($args, &$x)
- {
- global $core;
- $dao = new wsDAOCollection($core->con);
-
- $save = $_POST;
-
- $datas = array();
-
-
- $dir = WS_COLLECTIONS . '/apns/' . $_POST['collection_id'];
- if (!file_exists($dir)) {
- mkdir($dir, 0777, true);
- }
- $wdir = WS_COLLECTIONS . '/working/' . $_POST['collection_id'];
- if (!file_exists($wdir)) {
- mkdir($wdir, 0777, true);
- }
-
- if (isset($_FILES['apns_dev']) && !$_FILES['apns_dev']['error']) {
- move_uploaded_file($_FILES['apns_dev']['tmp_name'], $dir . '/apns_dev.pem');
- }
- if (isset($_FILES['apns_prod']) && $_FILES['apns_prod']['error']) {
- move_uploaded_file($_FILES['apns_prod']['tmp_name'], $dir . '/apns_prod.pem');
- }
-
- foreach ($_FILES as $t => $f) {
-
- if (!$_FILES[$t]['error']) {
- $ext = CubeIT_Files::getExtension($_FILES[$t]['name']);
- move_uploaded_file($_FILES[$t]['tmp_name'], $wdir . '/' . $t . '.' . $ext);
- $save['theme'][$t] = $t . '.' . $ext;
-
- if ($t == 'filesalt') {
- $d = $wdir . '/filesalt';
- CubeIT_Files::rmdir($d);
- $unzip = CubeIT_Util_Zip::extract($wdir . '/' . $t . '.' . $ext, $d);
- }
- }
- }
-
-
- foreach ($_POST['group'] as $gid => $group) {
- if ($gid && $gid == 'new_') {
- continue;
- }
-
- if (isset($group['publications'])) {
- $publications = array();
- foreach ($group['publications'] as $pid => $publication) {
- $publication = array('id' => $publication['id'], 'label' => $publication['label'], 'online' => isset($publication['online']));
- $publications[] = $publication;
- }
- $group['publications'] = $publications;
- } else {
- $group['publications'] = array($dao->_emptyPublication());
- }
-
- $datas[] = $group;
- }
-
- unset($save['group']);
-
- if (count($datas) == 0) {
- $datas = $dao->_emptyCollection();
- }
-
- $save['datas'] = $datas;
- $dao->sauve($save);
-
- $x->addReload();
- }
-
- public static function changeBookProprietaire($args, &$x)
- {
- return self::_changeProprietaire('book', $args[1], $_POST['proprietaire'], $x);
- }
-
- public static function changeCollectionProprietaire($args, &$x)
- {
- return self::_changeProprietaire('collection', $args[1], $_POST['proprietaire'], $x);
- }
-
- public static function _changeProprietaire($type, $id, $proprietaire, &$x)
- {
- global $core;
- if ($proprietaire == '') {
- $x->addError('book_proprietaire');
- return false;
- }
- $x->addOk('book_proprietaire');
-
- if ($type == "book") {
- $dao = new wsDAOBook($core->con);
- } elseif ($type == "collection") {
- $dao = new wsDAOCollection($core->con);
- }
-
- $dao->setProprietaire($id, $proprietaire);
-
- $x->addClosePopup();
- if ($type == 'book') {
- $x->addContent('listeBooks', wsUrl::listeBooks());
- } elseif ($type == "collection") {
- $x->addContent('listeCollections', wsUrl::listeCollections());
- }
- }
-
- public static function downbook($args, &$x)
- {
- global $core;
- $book_id = $args[1];
- $version = $args[2];
-
- $dao = new wsDAOBook($core->con);
- $book = $dao->selectById($book_id);
-
- if (!in_array($book->proprietaire_id, explode(',', $core->user->ws_rights))) {
- commonDroits::error();
- }
-
- if (isset($_POST['valide']) && $book->status < 1) {
- $book = $dao->setStatus($book_id, 1);
- }
-
- if (!wsDroits::admin()) {
- if ($book->status < 1) {
- $popup = commonAjax::form('downbook/' . $book_id . '/' . $version, __('Téléchargement de la publication'), wsUrl::valideDownload($book_id, $version), __('Télécharger'), 2, '', '', true);
-
- $x->addOpenPopup($popup);
- return;
- }
- }
-
- $exporter = new wsExporter();
- $exporter->export($book_id, $x, 'download', $version);
- }
-
- public static function statusBook($args, &$x)
- {
- global $core;
-
- $book_id = $args[1];
- $status = $args[2];
- if ($status == 2) {
- $x->addOpenPopup(self::formBookChooseProject($book_id));
- return;
- }
-
- $daoBook = new wsDAOBook($core->con);
- $daoBook->setStatus($book_id, $status);
-
- $x->addContent('listeBooks', wsUrl::listeBooks());
- }
-
- public static function formBookChooseProject($book_id)
- {
- return commonAjax::form('bookChooseProject', __("Selection d'un projet"), wsUrl::chooseBookProject($book_id), __('Suivant'), 3, '', '', true);
- }
-
- public static function bookChooseProject($args, &$x)
- {
- global $core;
-
- $book_id = $_POST['book_id'];
-
- if ($_POST['book_project'] == 0) {
- if (!isset($_POST['new_book_project_nom']) || $_POST['new_book_project_nom'] == '') {
- $x->addError('new_book_project_nom');
- return;
- }
-
- $core->loadExtranetClasses();
-
- $daoBook = new wsDAOBook($core->con);
- $book = $daoBook->selectById($book_id);
-
- $daoProjet = new extranetDAOProjet($core->con);
- $data = array();
- $data['nom'] = $_POST['new_book_project_nom'];
- $data['chef'] = $core->user->utilisateur_id;
- $data['client'] = $book->facturable_id;
- $data['devis'] = 0;
- $data['projet_id'] = 'new';
- $project = $daoProjet->sauve($data);
- } else {
- $project = $_POST['book_project'];
- }
-
- $x->addChangePopup(self::formBookChooseTache($book_id, $project));
- }
-
- public static function formBookChooseTache($book_id, $project)
- {
- return commonAjax::form('bookChooseTache', __("Selection d'une tâche"), wsUrl::chooseBookTache($book_id, $project), __('Enregistrer'), 3, '', '', true);
- }
-
- public static function bookChooseTache($args, &$x)
- {
- global $core;
-
- $book_id = $_POST['book_id'];
- $projet_id = $_POST['projet_id'];
-
- if ($_POST['tache'] == 0) {
- $ok = true;
-
- if (!isset($_POST['nom']) || $_POST['nom'] == '') {
- $x->addError('nom');
- $ok = false;
- } else {
- $x->addOk('nom');
- }
-
- if (!isset($_POST['budget']) || $_POST['budget'] == '') {
- $x->addError('budget');
- $ok = false;
- } else {
- $x->addOk('budget');
- }
-
- $core->loadExtranetClasses();
- $daoTache = new extranetDAOTache($core->con);
-
- $data = array();
- $data['tache_id'] = 'new';
- $data['projet'] = $projet_id;
- $data['nom'] = $_POST['nom'];
- $data['categorie'] = 8;
- $data['taux_journalier'] = TAUX_JOURNALIER;
- $data['budget'] = $_POST['budget'];
- $data['type'] = 0;
-
- $tache = $daoTache->sauve($data);
- } else {
- $tache = $_POST['tache'];
- }
-
- $daoBook = new wsDAOBook($core->con);
- $daoBook->setTache($book_id, $tache);
-
- $x->addClosePopup();
- $x->addContent('listeBooks', wsUrl::listeBooks());
- }
-
- public static function changeLang($args, &$x)
- {
- $x->addContent('formLang', wsUrl::formLang($_POST['lang']));
- }
-
- public static function saveLang($args, &$x)
- {
- global $core;
- $dao = new wsDAOLang($core->con);
- $data['lang_id'] = $_POST['lang'];
- $data['font'] = $_POST['font'];
- $data['charset'] = $_POST['charset'];
- $data['traductions'] = $_POST['msgid'];
- $data['nsis'] = $_POST['nsis'];
- $dao->sauve($data);
- $x->addAlert(__('Paramètres de la langue et traductions enregistrées'));
- }
-
- public static function demandeDevis($args, &$x)
- {
- global $core;
-
- $defaults = array('adresse' => '',
- 'code_postal' => '',
- 'ville' => '',
- 'pays' => 'INT',
- 'site' => '',
- 'telephone' => '',
- 'produits' => '',
- 'nombre_pages' => '',
- 'nombre_liens' => '',
- 'nombre_langues' => '',
- 'coupon' => '',
- 'fax' => '');
-
- $_POST = array_merge($defaults, $_POST);
-
- if (!self::valideDemandeDevis($x)) {
- $x->addAlert(sprintf(__("Une erreur s'est produite. Nous avons été averti de l'erreur que vous rencontrez. Vous pouvez nous contacter par e-mail à l'adresse suivante : %s"), '<a href="mailto:info@fluidbook.com">info@fluidbook.com</a>'));
- return;
- }
- $spam = (strlen($_POST['fax']) > 0);
- $_POST['spam'] = $spam ? 'Oui' : 'Non';
-
- if (!$spam) {
- // L'utilisateur est-il déjà dans la base ?
- $daoUtilisateur = new commonDAOUtilisateur($core->con);
- $utilisateur = $daoUtilisateur->selectByEmail($_POST['email']);
- if ($utilisateur != null) {
- $utilisateur_id = $utilisateur->utilisateur_id;
- } else {
- // Création de l'entreprise
- $daoEntreprise = new commonDAOEntreprise($core->con);
- $datas = array();
- $datas['entreprise_id'] = 'new';
- $datas['adresse'] = $_POST['adresse'];
- $datas['code_postal'] = $_POST['code_postal'];
- $datas['ville'] = $_POST['ville'];
- $datas['pays'] = $_POST['pays'];
- $datas['site'] = $_POST['site'];
- if ($_POST['rs'] == '') {
- $datas['nom'] = $_POST['prenom'] . ' ' . $_POST['nom'];
- } else {
- $datas['nom'] = $_POST['rs'];
- }
- $datas['site'] = $_POST['site'];
- $datas['ws_grade'] = 1;
- $datas['ws_admin'] = 1;
- $entreprise = $daoEntreprise->sauve($datas);
- // Création de l'utilisateur
- $datas = array();
- $datas['utilisateur_id'] = 'new';
- $datas['prenom'] = $_POST['prenom'];
- $datas['nom'] = $_POST['nom'];
- $datas['entreprise'] = $entreprise->entreprise_id;
- $datas['adresse'] = $_POST['adresse'];
- $datas['code_postal'] = $_POST['code_postal'];
- $datas['ville'] = $_POST['ville'];
- $datas['pays'] = $_POST['pays'];
- $datas['email'] = $_POST['email'];
- $datas['telephone'] = $_POST['telephone'];
- $datas['lang'] = $_POST['lang'];
- $datas['grade'] = 0;
- $datas['fax'] = '';
- $datas['mobile'] = '';
- $utilisateur = $daoUtilisateur->sauve($datas);
- $utilisateur_id = $utilisateur->utilisateur_id;
- }
-
- $datas = array();
- $datas['demande_id'] = 'new';
- $datas['type'] = $_POST['produits'];
- $datas['pages'] = $_POST['nombre_pages'];
- $datas['liens'] = $_POST['nombre_liens'];
- $datas['langues'] = $_POST['nombre_langues'];
- $datas['details'] = $_POST['detail'];
- $datas['coupon'] = $_POST['coupon'];
- $datas['utilisateur'] = $utilisateur_id;
- $datas['revendeur'] = 0;
- $datas['status'] = 0;
- $datas['administrateur'] = 0;
- $daoDemande = new wsDAODemande($core->con);
- $daoDemande->sauve($datas);
- }
-
- $fields = array(
- 'spam' => 'Demande SPAM',
- 'prenom' => 'Prenom',
- 'nom' => 'Nom',
- 'email' => 'E-mail',
- 'telephone' => 'Telephone',
- 'rs' => 'Société',
- 'site' => 'Site web',
- 'adresse' => 'Adresse',
- 'code_postal' => 'Code postal',
- 'ville' => 'Ville',
- 'pays' => 'Pays',
- 'produits' => 'Type',
- 'coupon' => 'Coupon',
- 'lang' => 'Langue du visiteur',
- 'nombre_liens' => 'Liens',
- 'nombre_pages' => 'Pages',
- 'nombre_langues' => 'Langues',
- 'contact_type' => 'Type de client',
- 'detail' => 'Commentaires',
- );
-
-
- $mail = new cubeMail();
- $mail->charset = 'UTF-8';
- $mail->from = $_POST['prenom'] . ' ' . $_POST['nom'] . '<' . $_POST['email'] . '>';
- $mail->to = FROM_EMAIL;
- if(!$spam) {
- $mail->subject = '[' . EMAIL_SUBJECT . '] Demande de devis';
- }else{
- $mail->subject = '[' . EMAIL_SUBJECT . '] ***SPAM*** Demande de devis';
- }
- $body = 'Une demande de devis a été envoyée avec les informations suivantes :' . "\r\n\r\n";
- foreach ($fields as $f => $d) {
- if ($_POST[$f] != '') {
- if ($f == 'pays') {
- $body .= ' * ' . $d . ' : ' . cubeCountry::getCountry($_POST[$f], 'fr') . "\r\n";
- } else if ($f == 'type') {
- $body .= ' * ' . $d . ' : ' . $core->demandes_type[$_POST[$f]] . "\r\n";
- } else {
- $body .= ' * ' . $d . ' : ' . $_POST[$f] . "\r\n";
- }
- }
- }
- $body .= "\r\n";
- if (!$spam) {
- $body .= 'Veuillez-vous rendre sur le Fluidbook Workshop (https://' . $_SERVER['HTTP_HOST'] . '/demandes) pour prendre en charge la demande ou la confier à un revendeur' . "\r\n";
- } else {
- $body .= 'Cette demande est un SPAM supposé. Elle n\'a pas été enregistrée dans le Fluidbook Workshop.' . "\r\n";
-
- }
- $mail->body = $body;
- $mail->send();
-
- if (isset($_POST['lang'])) {
- cubeLang::set($_POST['lang']);
- }
-
- $x->addAlert(__("Votre demande de devis a bien été envoyée. Merci pour l'intérêt que vous portez à Fluidbook."));
- cubeLang::set(LANG);
- $core->refreshWSUsersTree();
- }
-
- public static function valideDemandeDevis(&$x)
- {
- $d64 = base64_decode(str_replace(' ', '+', $_GET['devis_form']));
-
- $d = json_decode($d64);
- if (!$d) {
- $d = unserialize($d64);
- }
- if (!$d) {
- mail('tech@fluidbook.com', '[Fluidbook Workshop] Erreur envoi demande de devis', $_GET['devis_form'] . "\n\n" . utf8_decode($d64), 'From: tech@fluidbook.com');
- return false;
- }
-
- $d = cubeArray::array_flatten($d);
- foreach ($d as $k => $v) {
- $_POST[$k] = trim($v);
- }
- if (isset($_POST['pages'])) {
- $_POST['nombre_pages'] = $_POST['pages'];
- $_POST['nombre_liens'] = $_POST['liens'];
- $_POST['nombre_langues'] = $_POST['langues'];
- }
-
- if (!isset($_POST['rs'])) {
- $_POST['rs'] = $_POST['societe'];
- }
-
- if (!isset($_POST['detail'])) {
- $_POST['detail'] = $_POST['details'];
- }
-
- if (!isset($_POST['site'])) {
- $_POST['site'] = $_POST['site_internet'];
- }
- //file_put_contents(ROOT . '/cache/demandeDevis.txt', print_r($_POST, true));
- // Validation des champs de formulaires
- $ok = true;
- return $ok;
- }
-
- public static function searchDemandes($args, &$x)
- {
- $x->addContent('listeDemandes', wsUrl::listeDemandes());
- }
-
- public static function sortDemandes($args, &$x)
- {
- commonAjax::sort('demandes', $args[1]);
- $x->addContent('listeDemandes', wsUrl::listeDemandes());
- }
-
- public static function pageDemandes($args, &$x)
- {
- commonAjax::page('demandes', $args[1]);
- $x->addContent('listeDemandes', wsUrl::listeDemandes());
- }
-
- public static function parPageDemandes($args, &$x)
- {
- commonAjax::parPage('demandes', $_POST['par_page']);
- $x->addContent('listeDemandes', wsUrl::listeDemandes());
- }
-
- public static function parPageCollections($args, &$x)
- {
- commonAjax::parPage('collections', $_POST['par_page']);
- $x->addContent('listeCollections', wsUrl::listeCollections());
- }
-
- public static function supprimeDemande($args, &$x)
- {
- global $core;
- $demande_id = $args[1];
-
- $dao = new wsDAODemande($core->con);
- $dao->supprime($demande_id);
-
- $x->addContent('listeDemandes', wsUrl::listeDemandes());
- }
-
- public static function filtreDemandes($args, &$x)
- {
- if (isset($args[1]) && $args[1] == 'efface') {
- commonAjax::filtre('demandes');
- $x->addReload();
- return;
- } else {
- commonAjax::filtre('demandes', $_POST);
- $x->addContent('listeDemandes', wsUrl::listeDemandes());
- }
- }
-
- public static function formDemande($args, &$x)
- {
- if (!isset($args[2])) {
- $args[2] = null;
- }
- commonAjax::form('saveDemande', __("Edition d'une demande"), wsUrl::formDemande($args[1], $args[2]));
- }
-
- public static function lockDemande($args, &$x)
- {
- global $core;
- $dao = new wsDAODemande($core->con);
- $daoUtilisateur = new commonDAOUtilisateur($core->con);
-
- $demande = $dao->selectById($args[1]);
-
- if ($demande->administrateur != 0 && $demande->administrateur != $core->user->utilisateur_id) {
- $res = __("Cette demande est actuellement en cours d'édition par un autre administrateur");
- } elseif ($demande->status > 1) {
- $res = __("Cette demande est actuellement en cours de traitement");
- } else {
- // On place la demande comme en cours d'édition
- $dao->setAdministrateur($demande->demande_id, $core->user->utilisateur_id);
-
- // On vérifie que l'utilisateur n'est pas déjà géré par un revendeur
- $demandeur = $daoUtilisateur->selectById($demande->utilisateur, 'utilisateurs_entreprise');
- $administrateurs = $daoUtilisateur->selectWSAdministrateursId();
- if (!is_null($demandeur->ws_admin) && !in_array($demandeur->ws_admin, $administrateurs)) {
- // Si déjà géré par un revendeur
- $revendeur = $daoUtilisateur->selectById($demandeur->ws_admin, 'utilisateurs_entreprise');
- $actions[__('Je confie la demande à') . ' ' . $revendeur->rs . ' (' . $revendeur->prenom . ' ' . $revendeur->nom . ')'] = $demandeur->ws_admin;
- } else {
- $d = explode('@', $demandeur->email);
- $domain = mb_strtolower($d[1]);
-
- $liste = $daoUtilisateur->selectWSRevendeursFacturables();
- $revendeurs = array();
- $revendeurs_prio = array();
- foreach ($liste as $revendeur) {
- $k = $revendeur->rs . '(' . $revendeur->prenom . ' ' . $revendeur->nom . ')';
- $v = $revendeur->utilisateur_id;
- if (in_array($domain, $revendeur->ws_domains)) {
- $revendeurs_prio[$k] = $v;
- } else {
- $revendeurs[$k] = $v;
- }
- }
-
- $actions = array(__('Je vais me charger de cette demande') => $core->user->utilisateur_id);
- $actions[' '] = array();
- if (count($revendeurs_prio)) {
- $actions[__('Je confie la demande à (liste suggérée) ') . ' : '] = $revendeurs_prio;
- }
- if (count($revendeurs)) {
- $actions[__('Je confie la demande à ') . ' : '] = $revendeurs;
- }
- }
- $res = form::combo('revendeur', $actions);
- }
-
-
- $x->addContent('actionDemande', $res);
- }
-
- public static function saveDemande($args, &$x)
- {
- global $core;
- $dao = new wsDAODemande($core->con);
-
- if ($_POST['revendeur'] != $core->user->utilisateur_id) {
- $demande = $dao->setRevendeur($_POST['demande_id'], $_POST['revendeur']);
-
- $daoUtilisateur = new commonDAOUtilisateur($core->con);
- $r = $daoUtilisateur->selectById($_POST['revendeur']);
-
- self::sendDemandeToRevendeur($demande, $r);
- } else {
- $demande = $dao->setRevendeur($_POST['demande_id'], $_POST['revendeur']);
- }
-
- $x->addContent('listeDemandes', wsUrl::listeDemandes());
- $x->addClosePopup();
- }
-
- public static function sendDemandeToRevendeur($demande, $revendeur)
- {
- global $core;
-
- $dao = new commonDAOUtilisateur($core->con);
- $utilisateur = $dao->selectById($demande->utilisateur, 'utilisateurs_entreprise');
-
- $mail = new cubeMail();
- $mail->from = FROM_NAME . '<' . FROM_EMAIL . '>';
- $mail->subject = '[' . EMAIL_SUBJECT . '] ' . __('Demande de devis');
-
- $demande->type = $core->demandes_type[$demande->type];
-
- $body = wsDemande::asMailBody($demande, $utilisateur);
-
- $body .= "\r\n";
- $body .= __('Afin de nous confirmer que vous prenez en compte cette demande, veuillez cliquer sur le lien ci-dessous') . " : \r\n";
- $body .= 'http://' . $_SERVER['HTTP_HOST'] . '/reponseDemande/' . $demande->demande_id . '/' . $revendeur->utilisateur_id . "\r\n";
- $body .= "\r\n";
- $body .= __("Si dans un délai de deux jours ouvrés, vous n'avez pas accepté cette demande, nous nous réservons le droit de la prendre en charge.") . "\r\n";
-
- $mail->body = $body;
- $mail->to = $revendeur->email;
- $mail->bcc = MAIL_BCC;
- $mail->send();
- }
-
- public static function reponseDemande($args, &$x)
- {
- global $core;
-
- $demande_id = $args[1];
- $revendeur_id = $args[2];
- $reponse = $args[3];
- $reponse = $args[3];
-
- $dao = new wsDAODemande($core->con);
- $demande = $dao->selectById($demande_id);
-
- if ($demande->revendeur != $revendeur_id || $demande->revendeur != $core->user->utilisateur_id) {
- commonDroits::error();
- }
-
- if ($reponse == '0') {
- $dao->reinitDemande($demande_id);
- } else {
- $dao->accepteDemande($demande_id, $revendeur_id);
- }
-
- if (!isset($args[4])) {
- if ($response == '0') {
- $x->addRedirection(SITE_PATH);
- } else {
- $x->addReload();
- }
- } else {
- $x->addContent('listeDemandes', wsUrl::listeDemandes());
- }
- }
-
- public static function resetDemande($args, &$x)
- {
- global $core;
-
- $demande_id = $args[1];
-
- $dao = new wsDAODemande($core->con);
- $dao->reinitDemande($demande_id);
- $x->addContent('listeDemandes', wsUrl::listeDemandes());
- }
-
- public static function restoreLinksVersion($args, &$x)
- {
- global $core;
-
- set_time_limit(0);
-
- $book_id = $args[1];
- $time = $args[2];
-
- $dao = new wsDAODocument($core->con);
-
- if ($time == 'pdf') {
- if ($book_id < 10000) {
- $dao->setLinksFromOldFluidbook($book_id);
- } else {
- $dao->setFluidbookLinksFromCSV($book_id);
- }
- return;
- }
-
- $dao = new wsDAODocument($core->con);
- $dao->restoreLinksVersion($book_id, $time, $core->user->utilisateur_id);
- }
-
- public static function importLinksAsExcel($args)
- {
- set_time_limit(0);
-
- global $core;
- $book_id = $args[1];
-
- $fname = $_FILES['file']['name'];
- $ext = files::getExtension($fname);
- if ($ext == 'xlsx') {
- self::_importLinksAsExcel($book_id, $args);
- } else if ($ext == 'txt') {
- self::_importLinksAsAutobookmarkText($book_id, $args);
- }
- }
-
- protected static function _importLinksAsExcel($book_id)
- {
- global $core;
- $xls = new PHPExcel();
- $reader = new PHPExcel_Reader_Excel2007();
- $xls = $reader->load($_FILES['file']['tmp_name']);
-
- wsLinks::getLinksFromExcel($xls, $links, $rulers);
-
- $dao = new wsDAODocument($core->con);
- $dao->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), 'Import from excel', $core->user->utilisateur_id);
- }
-
- protected function _importLinksAsAutobookmarkText($book_id)
- {
- global $core;
-
- wsLinks::getLinksFromAutobookmarkText(file_get_contents($_FILES['file']['tmp_name']), $links, $rulers);
-
- $dao = new wsDAODocument($core->con);
- $dao->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), 'Import from fwstk text export', $core->user->utilisateur_id);
- }
-
- public static function offsetLinks($args, &$x)
- {
- global $core;
- $book_id = $args[1];
- $offset = $_POST['offset'];
- $from = $_POST['from'];
- $internal = isset($_POST['internal']);
-
- if ($internal) {
- $daoBook = new wsDAOBook($core->con);
- $book = $daoBook->selectById($book_id);
- $numerotation = explode(',', $book->numerotation);
- }
-
-
- $dao = new wsDAODocument($core->con);
- $dao->getLinksAndRulers($book_id, $links, $rulers);
- $rlinks = array();
- foreach ($links as $k => $link) {
- if ($link['page'] >= $from) {
- $link['page'] += $offset;
- }
- if ($internal && $link['type'] == 5) {
- if ($link['numerotation'] == 'physical') {
- if ($link['to'] >= $from) {
- $link['to'] += $offset;
- }
- } else {
- $ph = array_search($link['to'], $numerotation) + 1;
- if ($ph >= $from) {
- $ph += $offset;
- $vi = $numerotation[($ph - 1)];
- $link['to'] = $vi;
- }
- }
- }
-
- $rlinks[$k] = $link;
- }
-
- $rrulers = array();
- foreach ($rulers as $k => $ruler) {
- if ($ruler['page'] > $from) {
- $ruler['page'] += $offset;
- }
- $rrulers[$k] = $ruler;
- }
-
- $dao->setLinksAndRulers($book_id, $rlinks, $rrulers, 'Offset ' . $offset . ' pages from page # ' . $from, $core->user->utilisateur_id);
- $x->addEval('reloadLinks();');
- $x->addReload();
- }
-
- public static function exportbook($args, &$x)
- {
- if (isset($_POST['action'])) {
- $x->addChangePopup(commonAjax::form('exportbookExe', __("Exporter une publication"), self::formExportBook($_POST['book_id']), '', 2, '', '', true));
- return;
- }
- commonAjax::form('exportbookExe', __("Exporter une publication"), self::formExportBook($args[1]), '', 2);
- }
-
- public static function exportbookExe($args, &$x)
- {
-
- $dest = array('dir' => null, 'file' => null);
- if (isset($_POST['destination']) && is_array($_POST['destination'])) {
- $dest = array_merge($dest, $_POST['destination']);
- }
-
- $exporter = new wsExporter();
- $exporter->export($_POST['book_id'], $x, $_POST['action'], $_POST['version'], $dest['dir'], $dest['file']);
-
- $x->addClosePopup();
- }
-
- public static function formExportBook($book_id)
- {
- global $core;
- $choices = array(__('Télécharger') => 'download',
- __("Installer sur le serveur d'hébergement") => 'install_hosting',
- __("Installer sur l'espace de références") => 'install_references',
- __('Installer sur un serveur distant') => 'install_ftp',
- __('Envoyer vers un projet Phonegap Android') => 'phonegap_android',
- __('Envoyer vers un projet Phonegap iOS') => 'phonegap_ios'
- );
-
- $formatInstall = array('online' => false,
- 'v1' => false,
- 'html' => false,
- 'v2' => false,
- 'win-exe' => 'zip',
- 'win-ins' => 'exe',
- 'win-html' => 'zip',
- 'mac-exe' => 'zip',
- 'win-cd' => 'zip',
- 'phonegap' => 'zip',
- 'mac-exe-html' => 'zip',
- 'win-exe-html' => 'zip',
- 'win-inst-html' => 'zip',
- 'win-cd-html' => 'zip');
-
- $defaultVersion = isset($_POST['version']) ? $_POST['version'] : 'online';
- $version = '<tr><td class="right">' . __('Version') . '</td><td>' . form::combo('version', wsUrl::getFluidbookVersions(true), $defaultVersion) . '</td></tr>';
-
- $defaultAction = isset($_POST['action']) ? $_POST['action'] : 'download';
- $res = '<tr><td class="right">' . __('Action') . '</td><td>' . form::combo('action', $choices, $defaultAction) . form::hidden('book_id', $book_id) . '</td></tr>';
-
- $ae = explode('_', $defaultAction, 2);
- if ($ae[0] == 'phonegap') {
- $version = '';
- $defaultVersion = '';
- }
-
- $format = false;
- if ($defaultVersion != '') {
- $format = $formatInstall[$defaultVersion];
- }
- $displayFile = ($format !== false);
-
- if ($defaultAction != 'download') {
- $daoBook = new wsDAOBook($core->con);
- $book = $daoBook->selectById($book_id);
- if ($book->exportdatas == '') {
- $datas = array();
- } else {
- $datas = json_decode($book->exportdatas, true);
- }
-
- $res .= $version;
-
- if (!isset($datas[$defaultAction][$defaultVersion])) {
- $datas[$defaultAction][$defaultVersion] = array('dir' => '', 'file' => '');
- }
- $defaultDestination = $datas[$defaultAction][$defaultVersion];
- if ($defaultDestination == '' && isset($_POST['destination']) && $_POST['changed'] != 'version' && $_POST['changed'] != 'action') {
- $defaultDestination = $_POST['destination'];
- }
-
- if ($defaultDestination['dir'] == '' && ($defaultAction == 'install_hosting' || $defaultAction == 'install_references')) {
- $defaultDestination['dir'] = cubeText::str2URL($book->nom);
- }
-
- if ($defaultDestination['file'] == '') {
- $defaultDestination['file'] = cubeText::str2URL($book->nom) . '.' . $format;
- }
-
-
- switch ($defaultAction) {
- case 'install_hosting':
- $s = __("Serveur d'hébergement") . ' /';
- break;
- case 'install_references':
- $s = __('Espace des références') . ' /';
- break;
- case 'install_ftp':
- $s = __('Serveur FTP externe') . ' : ftp://';
- break;
- case 'phonegap_android':
- $s = __("Projet Phonegap Android") . ' /';
- break;
- case 'phonegap_ios':
- $s = __("Projet Phonegap iOS") . ' /';
- break;
- default:
- break;
- }
-
- $destinationFile = '';
- if ($displayFile) {
- $destinationFile = form::field(array('destination[file]', 'destination'), 50, 128, $defaultDestination['file']);
- }
-
- $res .= '<tr><td class="right"><em>' . $s . '</em></td><td>' . form::field(array('destination[dir]', 'destination'), 50, 128, $defaultDestination['dir']) . ' / ' . $destinationFile . '</td></tr>';
- } else {
- $res .= $version;
- }
-
- $res .= '<tr><td colspan="2" class="right">' . form::hidden('changed', '') . '<a href="#" class="submit">' . $core->typo->BoutonOK(__('Exporter')) . '</a></td></tr>';
-
- return $res;
- }
-
- public static function exportCollection($args, &$x)
- {
- $id = $args[1];
- $os = $args[2];
-
- $exporter = new wsExporter();
- $exporter->exportCollection($id, $os);
- }
-
- public static function publishCollection($args, &$x)
- {
- global $core;
- $collection = $_POST['collection'];
-
- $env = Zend_Mobile_Push_Apns::SERVER_SANDBOX_URI;
-
- // Notifications
-
- $apns = new Zend_Mobile_Push_Apns();
- if ($env == Zend_Mobile_Push_Apns::SERVER_SANDBOX_URI) {
- $c = 'dev';
- } else {
- $c = 'prod';
- }
- $apns->setCertificate(WS_COLLECTIONS . '/apns/' . $args[1] . '/apns_' . $c . '.pem');
- $apns->setCertificatePassphrase('apns');
- $apns->connect($env);
-
- $r = $core->con->select('SELECT token FROM book_collection_push WHERE platform=\'ios\' AND collection_id = \'' . $core->con->escape($collection) . '\'');
- while ($r->fetch()) {
- $m = new Zend_Mobile_Push_Message_Apns();
- $m->setBadge(5);
- $m->setToken($r->token);
- $m->setSound('none');
- $m->setId(microtime(true) * 1000);
- $apns->send($m);
- }
- $apns->close();
- }
-
- public function fluidbookAssets($args, &$x)
- {
- $id = $args[1];
- if (!$id) {
- $c = __('Entrez le numéro du fluidbook source pour sélectionner les fichiers à transférer');
- } else {
- $dr = opendir(WS_BOOKS . '/working/' . $id);
- $files = array();
- while ($f = readdir($dr)) {
- if ($f == '.' || $f == '..') {
- continue;
- }
-
- $files[$f] = $f;
- $checked[] = $f;
- }
-
- ksort($files);
-
- if (!count($files)) {
- $c = __('Aucun fichier à transférer');
- } else {
- $c = cubeForm::checkMultiple('files', $files, count($files), $checked);
- }
- }
-
- $x->addContent('f', $c);
- }
-
- public function copywsassets($args, &$x)
- {
- if (!isset($_POST['files']) || !count($_POST['files'])) {
- $x->addAlert(__('Aucun fichier sélectionné'));
- return;
- } elseif (!isset($_POST['dest']) || !$_POST['dest']) {
- $x->addAlert(__('Destination invalide'));
- return;
- }
-
- $d = WS_BOOKS . '/working/' . $_POST['dest'];
- if (!file_exists($d)) {
- mkdir($d, 0777, true);
- }
- $s = WS_BOOKS . '/working/' . $_POST['source'];
-
- foreach ($_POST['files'] as $f) {
- copy($s . '/' . $f, $d . '/' . $f);
- }
- $x->addAlert(__('Copie effectuée'));
- }
-
- public static function collectionVersionCreate($args, &$x)
- {
- global $core;
-
- $id = $args[1];
-
- $compiler = new wsHTML5AppCompiler($id);
- $time = $compiler->createVersion();
-
- file_put_contents(WS_COLLECTIONS . '/versions/' . $id . '/' . $time . '/composition.json', json_encode($compiler->collection->datas));
-
- $dao = new wsDAOCollection($core->con);
- $collection = $dao->selectById($id);
-
- $c = $core->con->openCursor('book_collection_compile');
- $c->collection_id = $id;
- $c->compile_date = $time;
- $c->online_ios = self::_maxVersion($collection->settings['v_ios']);
- $c->online_android = self::_maxVersion($collection->settings['v_android']);
- $c->insert();
-
- self::cleanCachesCollection($id);
-
- if ($_GET['ctrl']) {
- $_GET['ctrl'] = false;
- self::exportCollection(array('exportCollection', $id, 'ios'), $x);
- }
-
- if ($_GET['alt']) {
- $_GET['alt'] = false;
- self::exportCollection(array('exportCollection', $id, 'android'), $x);
- }
-
- $x->addReload();
- }
-
- public static function _maxVersion($vv)
- {
- $e = explode(',', $vv);
- $res = array();
- foreach ($e as $v) {
- $res[] = trim($v);
- }
- fb($res);
- usort($res, 'version_compare');
- return array_pop($res);
- }
-
- public static function collectionVersionPublish($args, &$x)
- {
- global $core;
-
- $id = $args[1];
-
- foreach ($_POST['version'] as $version => $oss) {
- $c = $core->con->openCursor('book_collection_compile');
- foreach ($oss as $os => $appver) {
- $c->{'online_' . $os} = $appver;
- }
- $c->update('WHERE collection_id=\'' . $core->con->escape($id) . '\' AND compile_date=\'' . $core->con->escape($version) . '\'');
- }
-
- self::cleanCachesCollection($id);
-
- $x->addReload();
- }
-
- protected static function cleanCachesCollection($id)
- {
- $ff = WS_COLLECTIONS . '/ws/' . $id . '.*';
- `rm $ff`;
- }
-
- public static function collectionVersionDelete($args, &$x)
- {
- global $core;
-
- $id = $args[1];
- $date = $args[2];
-
- if ($id && $date) {
- $d = WS_COLLECTIONS . '/versions/' . $id . '/' . $date;
- `rm -rf $d`;
- $core->con->execute('DELETE FROM book_collection_compile WHERE collection_id=\'' . $core->con->escape($id) . '\' AND compile_date=\'' . $core->con->escape($date) . '\'');
- }
- $x->addReload();
-
- self::cleanCachesCollection($id);
- }
-
+ public static function formClient($args, &$x)
+ {
+ global $core;
+ if ($args[1] == 'new') {
+ $extra = '';
+ } else {
+ $extra = '<p><br /><br /><br /></p><div id="listeContacts">' . wsUrl::listeContacts($args[1]) . '</div>';
+ }
+ $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>';
+
+ 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);
+ // Creation de l'entreprise
+ if ($_POST['entreprise_id'] == 'new') {
+ if (!isset($_POST['ws_admin']) || !$_POST['ws_admin']) {
+ $_POST['ws_admin'] = $core->user->utilisateur_id;
+ $_POST['ws_grade'] = 1;
+ }
+ }
+ if (isset($_POST['ws_admin']) && !$_POST['ws_admin']) {
+ $_POST['ws_admin'] = $core->user->utilisateur_id;
+ }
+ $entreprise = $dao->sauve($_POST);
+ // Si c'est une nouvelle entreprise, on crée également le contact
+ 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['site'] = $entreprise->site;
+ $data['grade'] = 0;
+ $daoClient = new commonDAOClient($core->con);
+ try {
+ $daoClient->sauve($data);
+ } catch (exception $e) {
+ $dao->supprime($entreprise->entreprise_id);
+ }
+ }
+
+ $core->refreshWSUsersTree();
+
+ $x->addContent('listeClients', wsUrl::listeClients());
+ $x->addClosePopup();
+ }
+
+ public static function saveContact($args, &$x)
+ {
+ global $core;
+ $dao = new commonDAOClient($core->con);
+ $client = $dao->sauve($_POST);
+ $x->addClosePopup();
+ $x->addContent('devisAdresseDisplay', commonUrl::adresse($client->utilisateur_id, null, 'devis'));
+ $x->addContent('factureAdresseDisplay', commonUrl::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[] = '<a href="#" class="popup" rel="formContact/' . $c->utilisateur_id . '">' . $c->prenom . ' ' . $c->nom . '</a>';
+ }
+
+ $core->refreshWSUsersTree();
+ $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]);
+
+ $core->refreshWSUsersTree();
+
+ $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_ws', $args[1]);
+ $x->addContent('listeClients', wsUrl::listeClients());
+ }
+
+ public static function sortCollections($args, &$x)
+ {
+ commonAjax::sort('collections', $args[1]);
+ $x->addContent('listeCollections', wsUrl::listeCollections());
+ }
+
+ public static function pageClient($args, &$x)
+ {
+ commonAjax::page('clients_ws', $args[1]);
+ $x->addContent('listeClients', wsUrl::listeClients());
+ }
+
+ public static function parPageClient($args, &$x)
+ {
+ commonAjax::parPage('clients_ws', $_POST['par_page']);
+ $x->addContent('listeClients', wsUrl::listeClients());
+ }
+
+ public static function filtreClients($args, &$x)
+ {
+ if (isset($args[1]) && $args[1] == 'efface') {
+ commonAjax::filtre('clients_ws');
+ $x->addReload();
+ return;
+ } else {
+ commonAjax::filtre('clients_ws', $_POST);
+ $x->addContent('listeClients', wsUrl::listeClients());
+ }
+ }
+
+ public static function supprimeBook($args, &$x)
+ {
+ global $core;
+ $dao = new wsDAOBook($core->con);
+ $dao->supprime($args[1]);
+ $x->addContent('listeBooks', wsUrl::listeBooks());
+ }
+
+ public static function searchPublications($args, &$x)
+ {
+ $x->addContent('listeBooks', wsUrl::listeBooks());
+ }
+
+ public static function pageBooks($args, &$x)
+ {
+ commonAjax::page('books', $args[1]);
+ $x->addContent('listeBooks', wsUrl::listeBooks());
+ }
+
+ public static function parPageBooks($args, &$x)
+ {
+ commonAjax::parPage('books', $_POST['par_page']);
+ $x->addContent('listeBooks', wsUrl::listeBooks());
+ }
+
+ public static function sortBooks($args, &$x)
+ {
+ commonAjax::sort('books', $args[1]);
+ $x->addContent('listeBooks', wsUrl::listeBooks());
+ }
+
+ public static function newBookForm($args, &$x)
+ {
+ commonAjax::form('newBook', __("Créer une nouvelle publication à partir d'une existante"), wsUrl::chooseExistingBook(), __('Créer une nouvelle publication'), 3);
+ }
+
+ public static function newCollectionForm($args, &$x)
+ {
+ commonAjax::form('saveCollection', __("Créer une nouvelle collection"), wsUrl::formCollection(), __('Créer une nouvelle collection'), 3);
+ }
+
+ public static function formChangeBookProprietaire($args, &$x)
+ {
+ commonAjax::form('changeBookProprietaire/' . $args[1], __("Modifier le propriétaire de la publication"), wsUrl::changeBookProprietaire($args[1]), __('Enregistrer'), 3);
+ }
+
+ public static function formChangeCollectionProprietaire($args, &$x)
+ {
+ commonAjax::form('changeCollectionProprietaire/' . $args[1], __("Modifier le propriétaire de la collection"), wsUrl::changeCollectionProprietaire($args[1]), __('Enregistrer'), 3);
+ }
+
+ public static function filtreBooks($args, &$x)
+ {
+ if (isset($args[1]) && $args[1] == 'efface') {
+ commonAjax::filtre('books');
+ $x->addReload();
+ return;
+ } else {
+ commonAjax::filtre('books', $_POST);
+ $x->addContent('listeBooks', wsUrl::listeBooks());
+ }
+ }
+
+ public static function newBook($args, &$x)
+ {
+ global $core;
+ $dao = new wsDAOBook($core->con);
+ if ($_POST['book'] != '') {
+ $book = $dao->duplicate($_POST['book'], $core->user->utilisateur_id, $_POST['title'], isset($_POST['pages']));
+ } else {
+ $book = $dao->creeEmpty($core->user->utilisateur_id, $core->user->lang, $_POST['title']);
+ }
+
+ $x->addClosePopup();
+ $x->addContent('listeBooks', wsUrl::listeBooks());
+ $x->addTruePopup(SITE_PATH . 'editor/' . $book->book_id);
+ }
+
+ public static function saveCollection($args, &$x)
+ {
+ global $core;
+ $dao = new wsDAOCollection($core->con);
+ $dao->sauve($_POST, $core->user->utilisateur_id);
+
+ $x->addClosePopup();
+ $x->addContent('listeCollections', wsUrl::listeCollections());
+ }
+
+ public static function saveCollectionComposition($args, &$x)
+ {
+ global $core;
+ $dao = new wsDAOCollection($core->con);
+
+ $save = $_POST;
+
+ $datas = array();
+
+
+ $dir = WS_COLLECTIONS . '/apns/' . $_POST['collection_id'];
+ if (!file_exists($dir)) {
+ mkdir($dir, 0777, true);
+ }
+ $wdir = WS_COLLECTIONS . '/working/' . $_POST['collection_id'];
+ if (!file_exists($wdir)) {
+ mkdir($wdir, 0777, true);
+ }
+
+ if (isset($_FILES['apns_dev']) && !$_FILES['apns_dev']['error']) {
+ move_uploaded_file($_FILES['apns_dev']['tmp_name'], $dir . '/apns_dev.pem');
+ }
+ if (isset($_FILES['apns_prod']) && $_FILES['apns_prod']['error']) {
+ move_uploaded_file($_FILES['apns_prod']['tmp_name'], $dir . '/apns_prod.pem');
+ }
+
+ foreach ($_FILES as $t => $f) {
+
+ if (!$_FILES[$t]['error']) {
+ $ext = CubeIT_Files::getExtension($_FILES[$t]['name']);
+ move_uploaded_file($_FILES[$t]['tmp_name'], $wdir . '/' . $t . '.' . $ext);
+ $save['theme'][$t] = $t . '.' . $ext;
+
+ if ($t == 'filesalt') {
+ $d = $wdir . '/filesalt';
+ CubeIT_Files::rmdir($d);
+ $unzip = CubeIT_Util_Zip::extract($wdir . '/' . $t . '.' . $ext, $d);
+ }
+ }
+ }
+
+
+ foreach ($_POST['group'] as $gid => $group) {
+ if ($gid && $gid == 'new_') {
+ continue;
+ }
+
+ if (isset($group['publications'])) {
+ $publications = array();
+ foreach ($group['publications'] as $pid => $publication) {
+ $publication = array('id' => $publication['id'], 'label' => $publication['label'], 'online' => isset($publication['online']));
+ $publications[] = $publication;
+ }
+ $group['publications'] = $publications;
+ } else {
+ $group['publications'] = array($dao->_emptyPublication());
+ }
+
+ $datas[] = $group;
+ }
+
+ unset($save['group']);
+
+ if (count($datas) == 0) {
+ $datas = $dao->_emptyCollection();
+ }
+
+ $save['datas'] = $datas;
+ $dao->sauve($save);
+
+ $x->addReload();
+ }
+
+ public static function changeBookProprietaire($args, &$x)
+ {
+ return self::_changeProprietaire('book', $args[1], $_POST['proprietaire'], $x);
+ }
+
+ public static function changeCollectionProprietaire($args, &$x)
+ {
+ return self::_changeProprietaire('collection', $args[1], $_POST['proprietaire'], $x);
+ }
+
+ public static function _changeProprietaire($type, $id, $proprietaire, &$x)
+ {
+ global $core;
+ if ($proprietaire == '') {
+ $x->addError('book_proprietaire');
+ return false;
+ }
+ $x->addOk('book_proprietaire');
+
+ if ($type == "book") {
+ $dao = new wsDAOBook($core->con);
+ } elseif ($type == "collection") {
+ $dao = new wsDAOCollection($core->con);
+ }
+
+ $dao->setProprietaire($id, $proprietaire);
+
+ $x->addClosePopup();
+ if ($type == 'book') {
+ $x->addContent('listeBooks', wsUrl::listeBooks());
+ } elseif ($type == "collection") {
+ $x->addContent('listeCollections', wsUrl::listeCollections());
+ }
+ }
+
+ public static function downbook($args, &$x)
+ {
+ global $core;
+ $book_id = $args[1];
+ $version = $args[2];
+
+ $dao = new wsDAOBook($core->con);
+ $book = $dao->selectById($book_id);
+
+ if (!in_array($book->proprietaire_id, explode(',', $core->user->ws_rights))) {
+ commonDroits::error();
+ }
+
+ if (isset($_POST['valide']) && $book->status < 1) {
+ $book = $dao->setStatus($book_id, 1);
+ }
+
+ if (!wsDroits::admin()) {
+ if ($book->status < 1) {
+ $popup = commonAjax::form('downbook/' . $book_id . '/' . $version, __('Téléchargement de la publication'), wsUrl::valideDownload($book_id, $version), __('Télécharger'), 2, '', '', true);
+
+ $x->addOpenPopup($popup);
+ return;
+ }
+ }
+
+ $exporter = new wsExporter();
+ $exporter->export($book_id, $x, 'download', $version);
+ }
+
+ public static function statusBook($args, &$x)
+ {
+ global $core;
+
+ $book_id = $args[1];
+ $status = $args[2];
+ if ($status == 2) {
+ $x->addOpenPopup(self::formBookChooseProject($book_id));
+ return;
+ }
+
+ $daoBook = new wsDAOBook($core->con);
+ $daoBook->setStatus($book_id, $status);
+
+ $x->addContent('listeBooks', wsUrl::listeBooks());
+ }
+
+ public static function formBookChooseProject($book_id)
+ {
+ return commonAjax::form('bookChooseProject', __("Selection d'un projet"), wsUrl::chooseBookProject($book_id), __('Suivant'), 3, '', '', true);
+ }
+
+ public static function bookChooseProject($args, &$x)
+ {
+ global $core;
+
+ $book_id = $_POST['book_id'];
+
+ if ($_POST['book_project'] == 0) {
+ if (!isset($_POST['new_book_project_nom']) || $_POST['new_book_project_nom'] == '') {
+ $x->addError('new_book_project_nom');
+ return;
+ }
+
+ $core->loadExtranetClasses();
+
+ $daoBook = new wsDAOBook($core->con);
+ $book = $daoBook->selectById($book_id);
+
+ $daoProjet = new extranetDAOProjet($core->con);
+ $data = array();
+ $data['nom'] = $_POST['new_book_project_nom'];
+ $data['chef'] = $core->user->utilisateur_id;
+ $data['client'] = $book->facturable_id;
+ $data['devis'] = 0;
+ $data['projet_id'] = 'new';
+ $project = $daoProjet->sauve($data);
+ } else {
+ $project = $_POST['book_project'];
+ }
+
+ $x->addChangePopup(self::formBookChooseTache($book_id, $project));
+ }
+
+ public static function formBookChooseTache($book_id, $project)
+ {
+ return commonAjax::form('bookChooseTache', __("Selection d'une tâche"), wsUrl::chooseBookTache($book_id, $project), __('Enregistrer'), 3, '', '', true);
+ }
+
+ public static function bookChooseTache($args, &$x)
+ {
+ global $core;
+
+ $book_id = $_POST['book_id'];
+ $projet_id = $_POST['projet_id'];
+
+ if ($_POST['tache'] == 0) {
+ $ok = true;
+
+ if (!isset($_POST['nom']) || $_POST['nom'] == '') {
+ $x->addError('nom');
+ $ok = false;
+ } else {
+ $x->addOk('nom');
+ }
+
+ if (!isset($_POST['budget']) || $_POST['budget'] == '') {
+ $x->addError('budget');
+ $ok = false;
+ } else {
+ $x->addOk('budget');
+ }
+
+ $core->loadExtranetClasses();
+ $daoTache = new extranetDAOTache($core->con);
+
+ $data = array();
+ $data['tache_id'] = 'new';
+ $data['projet'] = $projet_id;
+ $data['nom'] = $_POST['nom'];
+ $data['categorie'] = 8;
+ $data['taux_journalier'] = TAUX_JOURNALIER;
+ $data['budget'] = $_POST['budget'];
+ $data['type'] = 0;
+
+ $tache = $daoTache->sauve($data);
+ } else {
+ $tache = $_POST['tache'];
+ }
+
+ $daoBook = new wsDAOBook($core->con);
+ $daoBook->setTache($book_id, $tache);
+
+ $x->addClosePopup();
+ $x->addContent('listeBooks', wsUrl::listeBooks());
+ }
+
+ public static function changeLang($args, &$x)
+ {
+ $x->addContent('formLang', wsUrl::formLang($_POST['lang']));
+ }
+
+ public static function saveLang($args, &$x)
+ {
+ global $core;
+ $dao = new wsDAOLang($core->con);
+ $data['lang_id'] = $_POST['lang'];
+ $data['font'] = $_POST['font'];
+ $data['charset'] = $_POST['charset'];
+ $data['traductions'] = $_POST['msgid'];
+ $data['nsis'] = $_POST['nsis'];
+ $dao->sauve($data);
+ $x->addAlert(__('Paramètres de la langue et traductions enregistrées'));
+ }
+
+ public static function demandeDevis($args, &$x)
+ {
+ global $core;
+
+ $defaults = array('adresse' => '',
+ 'code_postal' => '',
+ 'ville' => '',
+ 'pays' => 'INT',
+ 'site' => '',
+ 'telephone' => '',
+ 'produits' => '',
+ 'nombre_pages' => '',
+ 'nombre_liens' => '',
+ 'nombre_langues' => '',
+ 'coupon' => '',
+ 'fax' => '');
+
+ $_POST = array_merge($defaults, $_POST);
+
+ if (!self::valideDemandeDevis($x)) {
+ $x->addAlert(sprintf(__("Une erreur s'est produite. Nous avons été averti de l'erreur que vous rencontrez. Vous pouvez nous contacter par e-mail à l'adresse suivante : %s"), '<a href="mailto:info@fluidbook.com">info@fluidbook.com</a>'));
+ return;
+ }
+ $spam = (strlen($_POST['fax']) > 0);
+ $_POST['spam'] = $spam ? 'Oui' : 'Non';
+
+ if (!$spam) {
+ // L'utilisateur est-il déjà dans la base ?
+ $daoUtilisateur = new commonDAOUtilisateur($core->con);
+ $utilisateur = $daoUtilisateur->selectByEmail($_POST['email']);
+ if ($utilisateur != null) {
+ $utilisateur_id = $utilisateur->utilisateur_id;
+ } else {
+ // Création de l'entreprise
+ $daoEntreprise = new commonDAOEntreprise($core->con);
+ $datas = array();
+ $datas['entreprise_id'] = 'new';
+ $datas['adresse'] = $_POST['adresse'];
+ $datas['code_postal'] = $_POST['code_postal'];
+ $datas['ville'] = $_POST['ville'];
+ $datas['pays'] = $_POST['pays'];
+ $datas['site'] = $_POST['site'];
+ if ($_POST['rs'] == '') {
+ $datas['nom'] = $_POST['prenom'] . ' ' . $_POST['nom'];
+ } else {
+ $datas['nom'] = $_POST['rs'];
+ }
+ $datas['site'] = $_POST['site'];
+ $datas['ws_grade'] = 1;
+ $datas['ws_admin'] = 1;
+ $entreprise = $daoEntreprise->sauve($datas);
+ // Création de l'utilisateur
+ $datas = array();
+ $datas['utilisateur_id'] = 'new';
+ $datas['prenom'] = $_POST['prenom'];
+ $datas['nom'] = $_POST['nom'];
+ $datas['entreprise'] = $entreprise->entreprise_id;
+ $datas['adresse'] = $_POST['adresse'];
+ $datas['code_postal'] = $_POST['code_postal'];
+ $datas['ville'] = $_POST['ville'];
+ $datas['pays'] = $_POST['pays'];
+ $datas['email'] = $_POST['email'];
+ $datas['telephone'] = $_POST['telephone'];
+ $datas['lang'] = $_POST['lang'];
+ $datas['grade'] = 0;
+ $datas['fax'] = '';
+ $datas['mobile'] = '';
+ $utilisateur = $daoUtilisateur->sauve($datas);
+ $utilisateur_id = $utilisateur->utilisateur_id;
+ }
+
+ $datas = array();
+ $datas['demande_id'] = 'new';
+ $datas['type'] = $_POST['produits'];
+ $datas['pages'] = $_POST['nombre_pages'];
+ $datas['liens'] = $_POST['nombre_liens'];
+ $datas['langues'] = $_POST['nombre_langues'];
+ $datas['details'] = $_POST['detail'];
+ $datas['coupon'] = $_POST['coupon'];
+ $datas['utilisateur'] = $utilisateur_id;
+ $datas['revendeur'] = 0;
+ $datas['status'] = 0;
+ $datas['administrateur'] = 0;
+ $daoDemande = new wsDAODemande($core->con);
+ $daoDemande->sauve($datas);
+ }
+
+ $fields = array(
+ 'spam' => 'Demande SPAM',
+ 'prenom' => 'Prenom',
+ 'nom' => 'Nom',
+ 'email' => 'E-mail',
+ 'telephone' => 'Telephone',
+ 'rs' => 'Société',
+ 'site' => 'Site web',
+ 'adresse' => 'Adresse',
+ 'code_postal' => 'Code postal',
+ 'ville' => 'Ville',
+ 'pays' => 'Pays',
+ 'produits' => 'Type',
+ 'coupon' => 'Coupon',
+ 'lang' => 'Langue du visiteur',
+ 'nombre_liens' => 'Liens',
+ 'nombre_pages' => 'Pages',
+ 'nombre_langues' => 'Langues',
+ 'contact_type' => 'Type de client',
+ 'detail' => 'Commentaires',
+ );
+
+
+ $mail = new cubeMail();
+ $mail->charset = 'UTF-8';
+ $mail->from = $_POST['prenom'] . ' ' . $_POST['nom'] . '<' . $_POST['email'] . '>';
+ $mail->to = FROM_EMAIL;
+ if (!$spam) {
+ $mail->subject = '[' . EMAIL_SUBJECT . '] Demande de devis';
+ } else {
+ $mail->subject = '[' . EMAIL_SUBJECT . '] ***SPAM*** Demande de devis';
+ }
+ $body = 'Une demande de devis a été envoyée avec les informations suivantes :' . "\r\n\r\n";
+ foreach ($fields as $f => $d) {
+ if ($_POST[$f] != '') {
+ if ($f == 'pays') {
+ $body .= ' * ' . $d . ' : ' . cubeCountry::getCountry($_POST[$f], 'fr') . "\r\n";
+ } else if ($f == 'type') {
+ $body .= ' * ' . $d . ' : ' . $core->demandes_type[$_POST[$f]] . "\r\n";
+ } else {
+ $body .= ' * ' . $d . ' : ' . $_POST[$f] . "\r\n";
+ }
+ }
+ }
+ $body .= "\r\n";
+ if (!$spam) {
+ $body .= 'Veuillez-vous rendre sur le Fluidbook Workshop (https://' . $_SERVER['HTTP_HOST'] . '/demandes) pour prendre en charge la demande ou la confier à un revendeur' . "\r\n";
+ } else {
+ $body .= 'Cette demande est un SPAM supposé. Elle n\'a pas été enregistrée dans le Fluidbook Workshop.' . "\r\n";
+
+ }
+ $mail->body = $body;
+ $mail->send();
+
+ if (isset($_POST['lang'])) {
+ cubeLang::set($_POST['lang']);
+ }
+
+ $x->addAlert(__("Votre demande de devis a bien été envoyée. Merci pour l'intérêt que vous portez à Fluidbook."));
+ cubeLang::set(LANG);
+ $core->refreshWSUsersTree();
+ }
+
+ public static function valideDemandeDevis(&$x)
+ {
+ $d64 = base64_decode(str_replace(' ', '+', $_GET['devis_form']));
+
+ $d = json_decode($d64);
+ if (!$d) {
+ $d = unserialize($d64);
+ }
+ if (!$d) {
+ mail('tech@fluidbook.com', '[Fluidbook Workshop] Erreur envoi demande de devis', $_GET['devis_form'] . "\n\n" . utf8_decode($d64), 'From: tech@fluidbook.com');
+ return false;
+ }
+
+ $d = cubeArray::array_flatten($d);
+ foreach ($d as $k => $v) {
+ $_POST[$k] = trim($v);
+ }
+ if (isset($_POST['pages'])) {
+ $_POST['nombre_pages'] = $_POST['pages'];
+ $_POST['nombre_liens'] = $_POST['liens'];
+ $_POST['nombre_langues'] = $_POST['langues'];
+ }
+
+ if (!isset($_POST['rs'])) {
+ $_POST['rs'] = $_POST['societe'];
+ }
+
+ if (!isset($_POST['detail'])) {
+ $_POST['detail'] = $_POST['details'];
+ }
+
+ if (!isset($_POST['site'])) {
+ $_POST['site'] = $_POST['site_internet'];
+ }
+ //file_put_contents(ROOT . '/cache/demandeDevis.txt', print_r($_POST, true));
+ // Validation des champs de formulaires
+ $ok = true;
+ return $ok;
+ }
+
+ public static function searchDemandes($args, &$x)
+ {
+ $x->addContent('listeDemandes', wsUrl::listeDemandes());
+ }
+
+ public static function sortDemandes($args, &$x)
+ {
+ commonAjax::sort('demandes', $args[1]);
+ $x->addContent('listeDemandes', wsUrl::listeDemandes());
+ }
+
+ public static function pageDemandes($args, &$x)
+ {
+ commonAjax::page('demandes', $args[1]);
+ $x->addContent('listeDemandes', wsUrl::listeDemandes());
+ }
+
+ public static function parPageDemandes($args, &$x)
+ {
+ commonAjax::parPage('demandes', $_POST['par_page']);
+ $x->addContent('listeDemandes', wsUrl::listeDemandes());
+ }
+
+ public static function parPageCollections($args, &$x)
+ {
+ commonAjax::parPage('collections', $_POST['par_page']);
+ $x->addContent('listeCollections', wsUrl::listeCollections());
+ }
+
+ public static function supprimeDemande($args, &$x)
+ {
+ global $core;
+ $demande_id = $args[1];
+
+ $dao = new wsDAODemande($core->con);
+ $dao->supprime($demande_id);
+
+ $x->addContent('listeDemandes', wsUrl::listeDemandes());
+ }
+
+ public static function filtreDemandes($args, &$x)
+ {
+ if (isset($args[1]) && $args[1] == 'efface') {
+ commonAjax::filtre('demandes');
+ $x->addReload();
+ return;
+ } else {
+ commonAjax::filtre('demandes', $_POST);
+ $x->addContent('listeDemandes', wsUrl::listeDemandes());
+ }
+ }
+
+ public static function formDemande($args, &$x)
+ {
+ if (!isset($args[2])) {
+ $args[2] = null;
+ }
+ commonAjax::form('saveDemande', __("Edition d'une demande"), wsUrl::formDemande($args[1], $args[2]));
+ }
+
+ public static function lockDemande($args, &$x)
+ {
+ global $core;
+ $dao = new wsDAODemande($core->con);
+ $daoUtilisateur = new commonDAOUtilisateur($core->con);
+
+ $demande = $dao->selectById($args[1]);
+
+ if ($demande->administrateur != 0 && $demande->administrateur != $core->user->utilisateur_id) {
+ $res = __("Cette demande est actuellement en cours d'édition par un autre administrateur");
+ } elseif ($demande->status > 1) {
+ $res = __("Cette demande est actuellement en cours de traitement");
+ } else {
+ // On place la demande comme en cours d'édition
+ $dao->setAdministrateur($demande->demande_id, $core->user->utilisateur_id);
+
+ // On vérifie que l'utilisateur n'est pas déjà géré par un revendeur
+ $demandeur = $daoUtilisateur->selectById($demande->utilisateur, 'utilisateurs_entreprise');
+ $administrateurs = $daoUtilisateur->selectWSAdministrateursId();
+ if (!is_null($demandeur->ws_admin) && !in_array($demandeur->ws_admin, $administrateurs)) {
+ // Si déjà géré par un revendeur
+ $revendeur = $daoUtilisateur->selectById($demandeur->ws_admin, 'utilisateurs_entreprise');
+ $actions[__('Je confie la demande à') . ' ' . $revendeur->rs . ' (' . $revendeur->prenom . ' ' . $revendeur->nom . ')'] = $demandeur->ws_admin;
+ } else {
+ $d = explode('@', $demandeur->email);
+ $domain = mb_strtolower($d[1]);
+
+ $liste = $daoUtilisateur->selectWSRevendeursFacturables();
+ $revendeurs = array();
+ $revendeurs_prio = array();
+ foreach ($liste as $revendeur) {
+ $k = $revendeur->rs . '(' . $revendeur->prenom . ' ' . $revendeur->nom . ')';
+ $v = $revendeur->utilisateur_id;
+ if (in_array($domain, $revendeur->ws_domains)) {
+ $revendeurs_prio[$k] = $v;
+ } else {
+ $revendeurs[$k] = $v;
+ }
+ }
+
+ $actions = array(__('Je vais me charger de cette demande') => $core->user->utilisateur_id);
+ $actions[' '] = array();
+ if (count($revendeurs_prio)) {
+ $actions[__('Je confie la demande à (liste suggérée) ') . ' : '] = $revendeurs_prio;
+ }
+ if (count($revendeurs)) {
+ $actions[__('Je confie la demande à ') . ' : '] = $revendeurs;
+ }
+ }
+ $res = form::combo('revendeur', $actions);
+ }
+
+
+ $x->addContent('actionDemande', $res);
+ }
+
+ public static function saveDemande($args, &$x)
+ {
+ global $core;
+ $dao = new wsDAODemande($core->con);
+
+ if ($_POST['revendeur'] != $core->user->utilisateur_id) {
+ $demande = $dao->setRevendeur($_POST['demande_id'], $_POST['revendeur']);
+
+ $daoUtilisateur = new commonDAOUtilisateur($core->con);
+ $r = $daoUtilisateur->selectById($_POST['revendeur']);
+
+ self::sendDemandeToRevendeur($demande, $r);
+ } else {
+ $demande = $dao->setRevendeur($_POST['demande_id'], $_POST['revendeur']);
+ }
+
+ $x->addContent('listeDemandes', wsUrl::listeDemandes());
+ $x->addClosePopup();
+ }
+
+ public static function sendDemandeToRevendeur($demande, $revendeur)
+ {
+ global $core;
+
+ $dao = new commonDAOUtilisateur($core->con);
+ $utilisateur = $dao->selectById($demande->utilisateur, 'utilisateurs_entreprise');
+
+ $mail = new cubeMail();
+ $mail->from = FROM_NAME . '<' . FROM_EMAIL . '>';
+ $mail->subject = '[' . EMAIL_SUBJECT . '] ' . __('Demande de devis');
+
+ $demande->type = $core->demandes_type[$demande->type];
+
+ $body = wsDemande::asMailBody($demande, $utilisateur);
+
+ $body .= "\r\n";
+ $body .= __('Afin de nous confirmer que vous prenez en compte cette demande, veuillez cliquer sur le lien ci-dessous') . " : \r\n";
+ $body .= 'http://' . $_SERVER['HTTP_HOST'] . '/reponseDemande/' . $demande->demande_id . '/' . $revendeur->utilisateur_id . "\r\n";
+ $body .= "\r\n";
+ $body .= __("Si dans un délai de deux jours ouvrés, vous n'avez pas accepté cette demande, nous nous réservons le droit de la prendre en charge.") . "\r\n";
+
+ $mail->body = $body;
+ $mail->to = $revendeur->email;
+ $mail->bcc = MAIL_BCC;
+ $mail->send();
+ }
+
+ public static function reponseDemande($args, &$x)
+ {
+ global $core;
+
+ $demande_id = $args[1];
+ $revendeur_id = $args[2];
+ $reponse = $args[3];
+ $reponse = $args[3];
+
+ $dao = new wsDAODemande($core->con);
+ $demande = $dao->selectById($demande_id);
+
+ if ($demande->revendeur != $revendeur_id || $demande->revendeur != $core->user->utilisateur_id) {
+ commonDroits::error();
+ }
+
+ if ($reponse == '0') {
+ $dao->reinitDemande($demande_id);
+ } else {
+ $dao->accepteDemande($demande_id, $revendeur_id);
+ }
+
+ if (!isset($args[4])) {
+ if ($response == '0') {
+ $x->addRedirection(SITE_PATH);
+ } else {
+ $x->addReload();
+ }
+ } else {
+ $x->addContent('listeDemandes', wsUrl::listeDemandes());
+ }
+ }
+
+ public static function resetDemande($args, &$x)
+ {
+ global $core;
+
+ $demande_id = $args[1];
+
+ $dao = new wsDAODemande($core->con);
+ $dao->reinitDemande($demande_id);
+ $x->addContent('listeDemandes', wsUrl::listeDemandes());
+ }
+
+ public static function restoreLinksVersion($args, &$x)
+ {
+ global $core;
+
+ set_time_limit(0);
+
+ $book_id = $args[1];
+ $time = $args[2];
+
+ $dao = new wsDAODocument($core->con);
+
+ if ($time == 'pdf') {
+ if ($book_id < 10000) {
+ $dao->setLinksFromOldFluidbook($book_id);
+ } else {
+ $dao->setFluidbookLinksFromCSV($book_id);
+ }
+ return;
+ }
+
+ $dao = new wsDAODocument($core->con);
+ $dao->restoreLinksVersion($book_id, $time, $core->user->utilisateur_id);
+ }
+
+ public static function importLinksAsExcel($args)
+ {
+ set_time_limit(0);
+
+ global $core;
+ $book_id = $args[1];
+
+ $fname = $_FILES['file']['name'];
+ $ext = files::getExtension($fname);
+ if ($ext == 'xlsx') {
+ self::_importLinksAsExcel($book_id, $args);
+ } else if ($ext == 'txt') {
+ self::_importLinksAsAutobookmarkText($book_id, $args);
+ }
+ }
+
+ protected static function _importLinksAsExcel($book_id)
+ {
+ global $core;
+ $xls = new PHPExcel();
+ $reader = new PHPExcel_Reader_Excel2007();
+ $xls = $reader->load($_FILES['file']['tmp_name']);
+
+ wsLinks::getLinksFromExcel($xls, $links, $rulers);
+
+ $dao = new wsDAODocument($core->con);
+ $dao->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), 'Import from excel', $core->user->utilisateur_id);
+ }
+
+ protected function _importLinksAsAutobookmarkText($book_id)
+ {
+ global $core;
+
+ wsLinks::getLinksFromAutobookmarkText(file_get_contents($_FILES['file']['tmp_name']), $links, $rulers);
+
+ $dao = new wsDAODocument($core->con);
+ $dao->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), 'Import from fwstk text export', $core->user->utilisateur_id);
+ }
+
+ public static function offsetLinks($args, &$x)
+ {
+ global $core;
+ $book_id = $args[1];
+ $offset = $_POST['offset'];
+ $from = $_POST['from'];
+ $internal = isset($_POST['internal']);
+
+ if ($internal) {
+ $daoBook = new wsDAOBook($core->con);
+ $book = $daoBook->selectById($book_id);
+ $numerotation = explode(',', $book->numerotation);
+ }
+
+
+ $dao = new wsDAODocument($core->con);
+ $dao->getLinksAndRulers($book_id, $links, $rulers);
+ $rlinks = array();
+ foreach ($links as $k => $link) {
+ if ($link['page'] >= $from) {
+ $link['page'] += $offset;
+ }
+ if ($internal && $link['type'] == 5) {
+ if ($link['numerotation'] == 'physical') {
+ if ($link['to'] >= $from) {
+ $link['to'] += $offset;
+ }
+ } else {
+ $ph = array_search($link['to'], $numerotation) + 1;
+ if ($ph >= $from) {
+ $ph += $offset;
+ $vi = $numerotation[($ph - 1)];
+ $link['to'] = $vi;
+ }
+ }
+ }
+
+ $rlinks[$k] = $link;
+ }
+
+ $rrulers = array();
+ foreach ($rulers as $k => $ruler) {
+ if ($ruler['page'] > $from) {
+ $ruler['page'] += $offset;
+ }
+ $rrulers[$k] = $ruler;
+ }
+
+ $dao->setLinksAndRulers($book_id, $rlinks, $rrulers, 'Offset ' . $offset . ' pages from page # ' . $from, $core->user->utilisateur_id);
+ $x->addEval('reloadLinks();');
+ $x->addReload();
+ }
+
+ public static function exportbook($args, &$x)
+ {
+ if (isset($_POST['action'])) {
+ $x->addChangePopup(commonAjax::form('exportbookExe', __("Exporter une publication"), self::formExportBook($_POST['book_id']), '', 2, '', '', true));
+ return;
+ }
+ commonAjax::form('exportbookExe', __("Exporter une publication"), self::formExportBook($args[1]), '', 2);
+ }
+
+ public static function exportbookExe($args, &$x)
+ {
+
+ $dest = array('dir' => null, 'file' => null);
+ if (isset($_POST['destination']) && is_array($_POST['destination'])) {
+ $dest = array_merge($dest, $_POST['destination']);
+ }
+
+ $exporter = new wsExporter();
+ $exporter->export($_POST['book_id'], $x, $_POST['action'], $_POST['version'], $dest['dir'], $dest['file']);
+
+ $x->addClosePopup();
+ }
+
+ public static function formExportBook($book_id)
+ {
+ global $core;
+ $choices = array(__('Télécharger') => 'download',
+ __("Installer sur le serveur d'hébergement") => 'install_hosting',
+ __("Installer sur l'espace de références") => 'install_references',
+ __('Installer sur un serveur distant') => 'install_ftp',
+ __('Envoyer vers un projet Phonegap Android') => 'phonegap_android',
+ __('Envoyer vers un projet Phonegap iOS') => 'phonegap_ios'
+ );
+
+ $formatInstall = array('online' => false,
+ 'v1' => false,
+ 'html' => false,
+ 'v2' => false,
+ 'win-exe' => 'zip',
+ 'win-ins' => 'exe',
+ 'win-html' => 'zip',
+ 'mac-exe' => 'zip',
+ 'win-cd' => 'zip',
+ 'phonegap' => 'zip',
+ 'mac-exe-html' => 'zip',
+ 'win-exe-html' => 'zip',
+ 'win-inst-html' => 'zip',
+ 'win-cd-html' => 'zip');
+
+ $defaultVersion = isset($_POST['version']) ? $_POST['version'] : 'online';
+ $version = '<tr><td class="right">' . __('Version') . '</td><td>' . form::combo('version', wsUrl::getFluidbookVersions(true), $defaultVersion) . '</td></tr>';
+
+ $defaultAction = isset($_POST['action']) ? $_POST['action'] : 'download';
+ $res = '<tr><td class="right">' . __('Action') . '</td><td>' . form::combo('action', $choices, $defaultAction) . form::hidden('book_id', $book_id) . '</td></tr>';
+
+ $ae = explode('_', $defaultAction, 2);
+ if ($ae[0] == 'phonegap') {
+ $version = '';
+ $defaultVersion = '';
+ }
+
+ $format = false;
+ if ($defaultVersion != '') {
+ $format = $formatInstall[$defaultVersion];
+ }
+ $displayFile = ($format !== false);
+
+ if ($defaultAction != 'download') {
+ $daoBook = new wsDAOBook($core->con);
+ $book = $daoBook->selectById($book_id);
+ if ($book->exportdatas == '') {
+ $datas = array();
+ } else {
+ $datas = json_decode($book->exportdatas, true);
+ }
+
+ $res .= $version;
+
+ if (!isset($datas[$defaultAction][$defaultVersion])) {
+ $datas[$defaultAction][$defaultVersion] = array('dir' => '', 'file' => '');
+ }
+ $defaultDestination = $datas[$defaultAction][$defaultVersion];
+ if ($defaultDestination == '' && isset($_POST['destination']) && $_POST['changed'] != 'version' && $_POST['changed'] != 'action') {
+ $defaultDestination = $_POST['destination'];
+ }
+
+ if ($defaultDestination['dir'] == '' && ($defaultAction == 'install_hosting' || $defaultAction == 'install_references')) {
+ $defaultDestination['dir'] = cubeText::str2URL($book->nom);
+ }
+
+ if ($defaultDestination['file'] == '') {
+ $defaultDestination['file'] = cubeText::str2URL($book->nom) . '.' . $format;
+ }
+
+
+ switch ($defaultAction) {
+ case 'install_hosting':
+ $s = __("Serveur d'hébergement") . ' /';
+ break;
+ case 'install_references':
+ $s = __('Espace des références') . ' /';
+ break;
+ case 'install_ftp':
+ $s = __('Serveur FTP externe') . ' : ftp://';
+ break;
+ case 'phonegap_android':
+ $s = __("Projet Phonegap Android") . ' /';
+ break;
+ case 'phonegap_ios':
+ $s = __("Projet Phonegap iOS") . ' /';
+ break;
+ default:
+ break;
+ }
+
+ $destinationFile = '';
+ if ($displayFile) {
+ $destinationFile = form::field(array('destination[file]', 'destination'), 50, 128, $defaultDestination['file']);
+ }
+
+ $res .= '<tr><td class="right"><em>' . $s . '</em></td><td>' . form::field(array('destination[dir]', 'destination'), 50, 128, $defaultDestination['dir']) . ' / ' . $destinationFile . '</td></tr>';
+ } else {
+ $res .= $version;
+ }
+
+ $res .= '<tr><td colspan="2" class="right">' . form::hidden('changed', '') . '<a href="#" class="submit">' . $core->typo->BoutonOK(__('Exporter')) . '</a></td></tr>';
+
+ return $res;
+ }
+
+ public static function exportCollection($args, &$x)
+ {
+ $id = $args[1];
+ $os = $args[2];
+
+ $exporter = new wsExporter();
+ $exporter->exportCollection($id, $os);
+ }
+
+ public static function publishCollection($args, &$x)
+ {
+ global $core;
+ $collection = $_POST['collection'];
+
+ $env = Zend_Mobile_Push_Apns::SERVER_SANDBOX_URI;
+
+ // Notifications
+
+ $apns = new Zend_Mobile_Push_Apns();
+ if ($env == Zend_Mobile_Push_Apns::SERVER_SANDBOX_URI) {
+ $c = 'dev';
+ } else {
+ $c = 'prod';
+ }
+ $apns->setCertificate(WS_COLLECTIONS . '/apns/' . $args[1] . '/apns_' . $c . '.pem');
+ $apns->setCertificatePassphrase('apns');
+ $apns->connect($env);
+
+ $r = $core->con->select('SELECT token FROM book_collection_push WHERE platform=\'ios\' AND collection_id = \'' . $core->con->escape($collection) . '\'');
+ while ($r->fetch()) {
+ $m = new Zend_Mobile_Push_Message_Apns();
+ $m->setBadge(5);
+ $m->setToken($r->token);
+ $m->setSound('none');
+ $m->setId(microtime(true) * 1000);
+ $apns->send($m);
+ }
+ $apns->close();
+ }
+
+ public function fluidbookAssets($args, &$x)
+ {
+ $id = $args[1];
+ if (!$id) {
+ $c = __('Entrez le numéro du fluidbook source pour sélectionner les fichiers à transférer');
+ } else {
+ $dr = opendir(WS_BOOKS . '/working/' . $id);
+ $files = array();
+ while ($f = readdir($dr)) {
+ if ($f == '.' || $f == '..') {
+ continue;
+ }
+
+ $files[$f] = $f;
+ $checked[] = $f;
+ }
+
+ ksort($files);
+
+ if (!count($files)) {
+ $c = __('Aucun fichier à transférer');
+ } else {
+ $c = cubeForm::checkMultiple('files', $files, count($files), $checked);
+ }
+ }
+
+ $x->addContent('f', $c);
+ }
+
+ public function copywsassets($args, &$x)
+ {
+ if (!isset($_POST['files']) || !count($_POST['files'])) {
+ $x->addAlert(__('Aucun fichier sélectionné'));
+ return;
+ } elseif (!isset($_POST['dest']) || !$_POST['dest']) {
+ $x->addAlert(__('Destination invalide'));
+ return;
+ }
+
+ $d = WS_BOOKS . '/working/' . $_POST['dest'];
+ if (!file_exists($d)) {
+ mkdir($d, 0777, true);
+ }
+ $s = WS_BOOKS . '/working/' . $_POST['source'];
+
+ foreach ($_POST['files'] as $f) {
+ copy($s . '/' . $f, $d . '/' . $f);
+ }
+ $x->addAlert(__('Copie effectuée'));
+ }
+
+ public static function collectionVersionCreate($args, &$x)
+ {
+ global $core;
+
+ $id = $args[1];
+
+ $compiler = new wsHTML5AppCompiler($id);
+ $time = $compiler->createVersion();
+
+ file_put_contents(WS_COLLECTIONS . '/versions/' . $id . '/' . $time . '/composition.json', json_encode($compiler->collection->datas));
+
+ $dao = new wsDAOCollection($core->con);
+ $collection = $dao->selectById($id);
+
+ $c = $core->con->openCursor('book_collection_compile');
+ $c->collection_id = $id;
+ $c->compile_date = $time;
+ $c->online_ios = self::_maxVersion($collection->settings['v_ios']);
+ $c->online_android = self::_maxVersion($collection->settings['v_android']);
+ $c->insert();
+
+ self::cleanCachesCollection($id);
+
+ if ($_GET['ctrl']) {
+ $_GET['ctrl'] = false;
+ self::exportCollection(array('exportCollection', $id, 'ios'), $x);
+ }
+
+ if ($_GET['alt']) {
+ $_GET['alt'] = false;
+ self::exportCollection(array('exportCollection', $id, 'android'), $x);
+ }
+
+ $x->addReload();
+ }
+
+ public static function _maxVersion($vv)
+ {
+ $e = explode(',', $vv);
+ $res = array();
+ foreach ($e as $v) {
+ $res[] = trim($v);
+ }
+ fb($res);
+ usort($res, 'version_compare');
+ return array_pop($res);
+ }
+
+ public static function collectionVersionPublish($args, &$x)
+ {
+ global $core;
+
+ $id = $args[1];
+
+ foreach ($_POST['version'] as $version => $oss) {
+ $c = $core->con->openCursor('book_collection_compile');
+ foreach ($oss as $os => $appver) {
+ $c->{'online_' . $os} = $appver;
+ }
+ $c->update('WHERE collection_id=\'' . $core->con->escape($id) . '\' AND compile_date=\'' . $core->con->escape($version) . '\'');
+ }
+
+ self::cleanCachesCollection($id);
+
+ $x->addReload();
+ }
+
+ protected static function cleanCachesCollection($id)
+ {
+ $ff = WS_COLLECTIONS . '/ws/' . $id . '.*';
+ `rm $ff`;
+ }
+
+ public static function collectionVersionDelete($args, &$x)
+ {
+ global $core;
+
+ $id = $args[1];
+ $date = $args[2];
+
+ if ($id && $date) {
+ $d = WS_COLLECTIONS . '/versions/' . $id . '/' . $date;
+ `rm -rf $d`;
+ $core->con->execute('DELETE FROM book_collection_compile WHERE collection_id=\'' . $core->con->escape($id) . '\' AND compile_date=\'' . $core->con->escape($date) . '\'');
+ }
+ $x->addReload();
+
+ self::cleanCachesCollection($id);
+ }
}
\ No newline at end of file