From: vincent@cubedesigners.com Date: Fri, 2 Jan 2015 17:13:14 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=c46343db4465ef8ca5371e196f7fe1db2b7f96a2;p=cubeextranet.git --- diff --git a/inc/commons/class.common.ajax.php b/inc/commons/class.common.ajax.php index 5e20a1bbf..866d36563 100644 --- a/inc/commons/class.common.ajax.php +++ b/inc/commons/class.common.ajax.php @@ -1,4 +1,4 @@ -a


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



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

'; - - commonAjax::form('saveClient', __("Edition d'un client"), wsUrl::formClient($args[1]), false, 2, '', $extra); - } - - public static function formContact($args, &$x) { - if (!isset($args[2])) { - $args[2] = null; - } - commonAjax::form('saveContact', __("Edition d'un contact"), wsUrl::formContact($args[1], $args[2])); - } - - public static function saveClient($args, &$x) { - global $core; - $dao = new commonDAOEntreprise($core->con); -// 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[] = '' . $c->prenom . ' ' . $c->nom . ''; - } - - $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; - } - } - - 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; - if (!self::valideDemandeDevis($x)) { - return; - } -// 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['utilisateur'] = $utilisateur_id; - $datas['revendeur'] = 0; - $datas['status'] = 0; - $datas['administrateur'] = 0; - $daoDemande = new wsDAODemande($core->con); - $daoDemande->sauve($datas); - - $fields = array('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', - 'lang' => 'Langue du visiteur', - 'nombre_liens' => 'Liens', - 'nombre_pages' => 'Pages', - 'nombre_langues' => 'Langues', - 'detail' => 'Commentaires'); - $mail = new cubeMail(); - $mail->charset = 'UTF-8'; - $mail->from = $_POST['prenom'] . ' ' . $_POST['nom'] . '<' . $_POST['email'] . '>'; - $mail->to = FROM_EMAIL; - $mail->subject = '[' . EMAIL_SUBJECT . '] 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"; - $body .= 'Veuillez-vous rendre sur le Fluidbook Workshop (http://' . $_SERVER['HTTP_HOST'] . '/demandes) pour prendre en charge la demande ou la confier à un revendeur' . "\r\n"; - $mail->body = $body; - $mail->send(); - - $x->addAlert(__("Votre demande de devis a bien été envoyée. Merci pour l'intérêt que vous portez à Fluidbook.")); - $core->refreshWSUsersTree(); - } - - public static function valideDemandeDevis(&$x) { - $d = unserialize(base64_decode($_GET['devis_form'])); - $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]; - - $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; - } - - - wsLinks::getLinksAndRulers($book_id, $links, $rulers, $time); - - $dao = new wsDAODocument($core->con); - $dao->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), 'Restore links from ' . date('Y-m-d H:i:s', $time), $core->user->utilisateur_id); - } - - public static function importLinksAsExcel($args) { - set_time_limit(0); - - global $core; - $book_id = $args[1]; - - $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); - } - - 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->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', - 'mac-exe' => 'zip', - 'win-cd' => 'zip', - 'phonegap' => 'zip'); - - $defaultVersion = isset($_POST['version']) ? $_POST['version'] : 'online'; - $version = '' . __('Version') . '' . form::combo('version', wsUrl::getFluidbookVersions(true), $defaultVersion) . ''; - - $defaultAction = isset($_POST['action']) ? $_POST['action'] : 'download'; - $res = '' . __('Action') . '' . form::combo('action', $choices, $defaultAction) . form::hidden('book_id', $book_id) . ''; - - $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 .= '' . $s . '' . form::field(array('destination[dir]', 'destination'), 50, 128, $defaultDestination['dir']) . ' / ' . $destinationFile . ''; - } else { - $res.=$version; - } - - $res .= '' . form::hidden('changed', '') . '' . $core->typo->BoutonOK(__('Exporter')) . ''; - - 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); - - $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); - } - -} - +


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



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

'; + + commonAjax::form('saveClient', __("Edition d'un client"), wsUrl::formClient($args[1]), false, 2, '', $extra); + } + + public static function formContact($args, &$x) { + if (!isset($args[2])) { + $args[2] = null; + } + commonAjax::form('saveContact', __("Edition d'un contact"), wsUrl::formContact($args[1], $args[2])); + } + + public static function saveClient($args, &$x) { + global $core; + $dao = new commonDAOEntreprise($core->con); +// 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[] = '' . $c->prenom . ' ' . $c->nom . ''; + } + + $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; + } + } + + 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; + if (!self::valideDemandeDevis($x)) { + return; + } +// 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['utilisateur'] = $utilisateur_id; + $datas['revendeur'] = 0; + $datas['status'] = 0; + $datas['administrateur'] = 0; + $daoDemande = new wsDAODemande($core->con); + $daoDemande->sauve($datas); + + $fields = array('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', + 'lang' => 'Langue du visiteur', + 'nombre_liens' => 'Liens', + 'nombre_pages' => 'Pages', + 'nombre_langues' => 'Langues', + 'detail' => 'Commentaires'); + $mail = new cubeMail(); + $mail->charset = 'UTF-8'; + $mail->from = $_POST['prenom'] . ' ' . $_POST['nom'] . '<' . $_POST['email'] . '>'; + $mail->to = FROM_EMAIL; + $mail->subject = '[' . EMAIL_SUBJECT . '] 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"; + $body .= 'Veuillez-vous rendre sur le Fluidbook Workshop (http://' . $_SERVER['HTTP_HOST'] . '/demandes) pour prendre en charge la demande ou la confier à un revendeur' . "\r\n"; + $mail->body = $body; + $mail->send(); + + $x->addAlert(__("Votre demande de devis a bien été envoyée. Merci pour l'intérêt que vous portez à Fluidbook.")); + $core->refreshWSUsersTree(); + } + + public static function valideDemandeDevis(&$x) { + $d = unserialize(base64_decode($_GET['devis_form'])); + $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]; + + $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; + } + + wsLinks::getLinksAndRulers($book_id, $links, $rulers, $time); + + $dao = new wsDAODocument($core->con); + $dao->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), 'Restore links from ' . date('Y-m-d H:i:s', $time), $core->user->utilisateur_id); + } + + public static function importLinksAsExcel($args) { + set_time_limit(0); + + global $core; + $book_id = $args[1]; + + $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); + } + + 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', + 'mac-exe' => 'zip', + 'win-cd' => 'zip', + 'phonegap' => 'zip'); + + $defaultVersion = isset($_POST['version']) ? $_POST['version'] : 'online'; + $version = '' . __('Version') . '' . form::combo('version', wsUrl::getFluidbookVersions(true), $defaultVersion) . ''; + + $defaultAction = isset($_POST['action']) ? $_POST['action'] : 'download'; + $res = '' . __('Action') . '' . form::combo('action', $choices, $defaultAction) . form::hidden('book_id', $book_id) . ''; + + $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 .= '' . $s . '' . form::field(array('destination[dir]', 'destination'), 50, 128, $defaultDestination['dir']) . ' / ' . $destinationFile . ''; + } else { + $res.=$version; + } + + $res .= '' . form::hidden('changed', '') . '' . $core->typo->BoutonOK(__('Exporter')) . ''; + + 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); + + $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 diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index f0e96506b..dd09eaf13 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -642,6 +642,61 @@ class wsMaintenance { } } + public static function copyComposition($args) { + global $core; + + $from = $args[0]; + $to = $args[1]; + + $r = $core->con->select('SELECT * FROM book_pages_versions WHERE book_id=\'' . $core->con->escape($from) . '\' AND composition!=\'a:0:{}\' ORDER BY `update` DESC LIMIT 1'); + if (!$r->count()) { + return; + } + + $comp = unserialize($r->composition); + + $docs = array(); + foreach ($comp as $book_page => $infos) { + $docs[$infos['document_id']] = true; + } + foreach ($docs as $doc => $v) { + $r = $core->con->select('SELECT MAX(document_id) AS document_id FROM documents'); + $newid = $r->document_id + 1; + + self::_duplicateLines('documents', 'document_id', $doc, $newid); + self::_duplicateLines('document_links', 'document_id', $doc, $newid); + self::_duplicateLines('document_links_versions', 'document_id', $doc, $newid); + + $f = WS_DOCS . '/' . $doc; + $t = WS_DOCS . '/' . $newid; + + `cp -r $f $t`; + + $docs[$doc] = $newid; + } + + $core->con->execute('DELETE FROM book_pages WHERE book_id=\'' . $core->con->escape($to) . '\''); + + $c = $core->con->openCursor('book_pages'); + $c->book_id = $to; + foreach ($comp as $book_page => $infos) { + $c->book_page = $book_page; + $c->document_id = $docs[$infos['document_id']]; + $c->document_page = $infos['document_page']; + $c->insert(); + } + } + + protected static function _duplicateLines($table, $key, $currentKey, $newKey) { + global $core; + $tmptable = 'tmptable_' . $table . '_' . $newKey; + + $core->con->execute('CREATE TEMPORARY TABLE ' . $tmptable . ' SELECT * FROM ' . $table . ' WHERE ' . $key . ' = ' . $currentKey); + $core->con->execute('UPDATE ' . $tmptable . ' SET ' . $key . ' = ' . $newKey); + $core->con->execute('INSERT INTO ' . $table . ' SELECT * FROM ' . $tmptable); + $core->con->execute('DROP TEMPORARY TABLE IF EXISTS ' . $tmptable); + } + public static function restoreComposition($args) { global $core; $book_id = $args[0]; diff --git a/js/ws.js b/js/ws.js index 2d16d9439..ea8f3dc7e 100644 --- a/js/ws.js +++ b/js/ws.js @@ -1,169 +1,173 @@ -TO_LOAD[TO_LOAD.length] = 'load_ws();'; -TO_LOAD_ONCE[TO_LOAD_ONCE.length] = 'load_ws_once();'; -FIRST_LOAD = true; - -function load_ws_once() { - $(document).on('change', 'form[action="exportbook"] select, form[action="exportbookExe"] select', function() { - var form = $(this).parents('form'); - $(form).find('#changed').val($(this).attr('name')); - $(form).attr('action', 'exportbook').submit().attr('action', 'exportbookExe'); - }); - - if ($("#collection").length > 0) { - $("#collection>form>ul").sortable({ - cancel: 'h1', - axis: 'y', - handle: '.move' - }); - - - $(document).on('click', "#collection>form>ul a.delete", function() { - $(this).parents('li:first').remove(); - return false; - }); - - $(document).on('click', "#collection>form>ul a.add", function() { - var publication = $(this).parents('li:first'); - var group = $(publication).parents('.group'); - var clone = $(".group.empty .publication").clone().get(0).outerHTML; - - clone = clone.replace(/pnew_/gi, $(group).find('.publication').length); - clone = clone.replace(/new_/gi, $(group).data('group')); - - $(publication).after(clone); - - initAutocompleteCollection(); - return false; - }); - - $("#collection>form>ul>li").each(function() { - initGroup($(this)); - }); - - - var newCounter = 1; - - $("#newGroup").click(function() { - var g = $(".group.empty").clone(); - var html = g.get(0).outerHTML; - html = html.replace(/pnew_/gi, '0'); - html = html.replace(/new_/gi, "new_" + newCounter); - g = $(html); - $(g).removeClass('empty'); - $("#collection>form>ul").append(g); - - initGroup(g); - - newCounter++; - return false; - }); - } -} - -function initGroup(group) { - $(group).find("ul").sortable({ - cancel: 'h1', - axis: 'y', - handle: '.move', - connectWith: '#collection>form>ul ul' - }); - - initAutocompleteCollection(); -} - -function initAutocompleteCollection() { - try { - $('.publication_id:visible').not('.ac_input').autocompletej(SITE_PATH + 'autocomplete/book', { - cacheLength: 0, - maxItemsToShow: 15, - onFindValue: findBook, - onItemSelect: findBook - }); - } catch (err) { - - } -} - -function load_ws() { - if ($("#book_nom").length) { - $("#book_nom").autocompletej(SITE_PATH + 'autocomplete/book', { - cacheLength: 0, - maxItemsToShow: 15, - onFindValue: findBook, - onItemSelect: findBook - }); - } - - if ($("#book_proprietaire").length) { - $("#book_proprietaire").autocompletej(SITE_PATH + 'autocomplete/wsuser', { - cacheLength: 0, - maxItemsToShow: 15, - onFindValue: findProprietaire, - onItemSelect: findProprietaire - }); - } - - - if ($("#ws_admin_nom").length > 0) { - $("#ws_admin_nom").autocompletej(SITE_PATH + 'autocomplete/wsadmin', { - cacheLength: 0, - maxItemsToShow: 15, - onFindValue: findWSAdmin, - onItemSelect: findWSAdmin - }); - } - - $("#importLinksAsExcel,#offsetLinks").submit(function() { - $(this).ajaxSubmit({ - url: SITE_PATH + 'ajax/' + $(this).attr('action'), - success: function(data) { - window.opener.document.getElementById("composerSwf").reloadLinks(); - window.close(); - } - }); - return false; - }); - - $(".restoreLink").click(restoreLink); - - $(".hide_new_value").change(function() { - if ($(this).val() == 0) { - $(".new").show(); - } else { - $(".new").hide(); - } - }); -} - -function restoreLink() { - $.ajax({ - url: SITE_PATH + 'ajax/restoreLinksVersion/' + $(this).attr('rel'), - success: function(data) { - window.opener.document.getElementById("composerSwf").reloadLinks(); - window.close(); - } - }); - return false; -} - -function findProprietaire(li) { - var p = li.selectValue.split(' - '); - if (p.length <= 1) { - return; - } - var user_id = parseInt(p[0]); - $("#proprietaire").val(user_id); -} - -function findBook(li, input) { - - var book = li.selectValue.split(' - '); - if (book.length <= 1) { - return; - } - - var book_id = parseInt(book[0]); - var next = $(input).next('input[type="hidden"]:first'); - fb(input); - $(next).val(book_id); +TO_LOAD[TO_LOAD.length] = 'load_ws();'; +TO_LOAD_ONCE[TO_LOAD_ONCE.length] = 'load_ws_once();'; +FIRST_LOAD = true; + +function load_ws_once() { + $(document).on('change', 'form[action="exportbook"] select, form[action="exportbookExe"] select', function () { + var form = $(this).parents('form'); + $(form).find('#changed').val($(this).attr('name')); + $(form).attr('action', 'exportbook').submit().attr('action', 'exportbookExe'); + }); + + if ($("#collection").length > 0) { + $("#collection>form>ul").sortable({ + cancel: 'h1', + axis: 'y', + handle: '.move' + }); + + + $(document).on('click', "#collection>form>ul a.delete", function () { + $(this).parents('li:first').remove(); + return false; + }); + + $(document).on('click', "#collection>form>ul a.add", function () { + var publication = $(this).parents('li:first'); + var group = $(publication).parents('.group'); + var clone = $(".group.empty .publication").clone().get(0).outerHTML; + + clone = clone.replace(/pnew_/gi, $(group).find('.publication').length); + clone = clone.replace(/new_/gi, $(group).data('group')); + + $(publication).after(clone); + + initAutocompleteCollection(); + return false; + }); + + $("#collection>form>ul>li").each(function () { + initGroup($(this)); + }); + + + var newCounter = 1; + + $("#newGroup").click(function () { + var g = $(".group.empty").clone(); + var html = g.get(0).outerHTML; + html = html.replace(/pnew_/gi, '0'); + html = html.replace(/new_/gi, "new_" + newCounter); + g = $(html); + $(g).removeClass('empty'); + $("#collection>form>ul").append(g); + + initGroup(g); + + newCounter++; + return false; + }); + } +} + +function initGroup(group) { + $(group).find("ul").sortable({ + cancel: 'h1', + axis: 'y', + handle: '.move', + connectWith: '#collection>form>ul ul' + }); + + initAutocompleteCollection(); +} + +function initAutocompleteCollection() { + try { + $('.publication_id:visible').not('.ac_input').autocompletej(SITE_PATH + 'autocomplete/book', { + cacheLength: 0, + maxItemsToShow: 15, + onFindValue: findBook, + onItemSelect: findBook + }); + } catch (err) { + + } +} + +function load_ws() { + if ($("#book_nom").length) { + $("#book_nom").autocompletej(SITE_PATH + 'autocomplete/book', { + cacheLength: 0, + maxItemsToShow: 15, + onFindValue: findBook, + onItemSelect: findBook + }); + } + + if ($("#book_proprietaire").length) { + $("#book_proprietaire").autocompletej(SITE_PATH + 'autocomplete/wsuser', { + cacheLength: 0, + maxItemsToShow: 15, + onFindValue: findProprietaire, + onItemSelect: findProprietaire + }); + } + + + if ($("#ws_admin_nom").length > 0) { + $("#ws_admin_nom").autocompletej(SITE_PATH + 'autocomplete/wsadmin', { + cacheLength: 0, + maxItemsToShow: 15, + onFindValue: findWSAdmin, + onItemSelect: findWSAdmin + }); + } + + $("#importLinksAsExcel,#offsetLinks").submit(function () { + $(this).ajaxSubmit({ + url: SITE_PATH + 'ajax/' + $(this).attr('action'), + success: function (data) { + window.opener.document.getElementById("composerSwf").reloadLinks(); + window.close(); + } + }); + return false; + }); + + $(".restoreLink").click(restoreLink); + + $(".hide_new_value").change(function () { + if ($(this).val() == 0) { + $(".new").show(); + } else { + $(".new").hide(); + } + }); +} + +function restoreLink() { + $.ajax({ + url: SITE_PATH + 'ajax/restoreLinksVersion/' + $(this).attr('rel'), + success: function (data) { + reloadLinks(); + window.close(); + } + }); + return false; +} + +function reloadLinks() { + window.opener.document.getElementById("composerSwf").reloadLinks(); +} + +function findProprietaire(li) { + var p = li.selectValue.split(' - '); + if (p.length <= 1) { + return; + } + var user_id = parseInt(p[0]); + $("#proprietaire").val(user_id); +} + +function findBook(li, input) { + + var book = li.selectValue.split(' - '); + if (book.length <= 1) { + return; + } + + var book_id = parseInt(book[0]); + var next = $(input).next('input[type="hidden"]:first'); + fb(input); + $(next).val(book_id); } \ No newline at end of file