From: vincent@cubedesigners.com Date: Tue, 19 Mar 2019 14:11:20 +0000 (+0000) Subject: wait #2475 @4 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=f52ecffc91f59eff7d8a282e536601e39a4a7592;p=cubeextranet.git wait #2475 @4 --- diff --git a/inc/commons/class.common.ajax.php b/inc/commons/class.common.ajax.php index c7474d8b1..47fae4be1 100644 --- a/inc/commons/class.common.ajax.php +++ b/inc/commons/class.common.ajax.php @@ -3,394 +3,441 @@ class commonAjax { - public static function form($action, $titre, $form, $bouton = null, $cols = 2, $class = '', $extra = '', $return = false) - { - global $core; - if ($class != '') { - $class = ' ' . $class; - } - $bouton = is_null($bouton) ? __('Enregister') : $bouton; - $colspan = $cols > 2 ? ' colspan="' . ($cols - 1) . '"' : ''; - $res = commonPage::bh(); - $res .= '
'; - $res .= ''; - $res .= '

' . $titre . '

'; - $res .= $form; - if ($bouton) { - $res .= ''; - } - $res .= '
' . cubeMedia::image(IMG . '/close.png') . '
' . $core->typo->BoutonOK($bouton) . '
'; - $res .= $extra; - $res .= '
'; - $res .= commonPage::bf(); - - if (!$return) { - echo $res; - exit; - } - return $res; - } - - public static function page($liste, $page) - { - global $core; - $core->user->changeSettings($liste, 'page', $page); - $core->sauvePreferencesUtilisateur(); - } - - public static function parPage($liste, $nb) - { - global $core; - $core->user->changeSettings($liste, 'par_page', $nb); - $core->user->changeSettings($liste, 'page', 1); - $core->sauvePreferencesUtilisateur(); - } - - public static function sort($liste, $orderby) - { - global $core; - $settings = $core->user->getSettings($liste); - if ($orderby == 'facture_id') { - $orderby = 'CAST(facture_id AS SIGNED)'; - } - - if ($settings['orderby'] == $orderby) { - $sens = ($settings['sens'] == 'ASC') ? 'DESC' : 'ASC'; - $core->user->changeSettings($liste, 'orderby', $orderby); - $core->user->changeSettings($liste, 'sens', $sens); - } else { - $core->user->changeSettings($liste, 'orderby', $orderby); - $core->user->changeSettings($liste, 'sens', 'ASC'); - } - $core->sauvePreferencesUtilisateur(); - } - - public static function filtre($liste, $data = null) - { - global $core; - $core->user->changeSettings($liste, 'filtres', $data); - $core->user->changeSettings($liste, 'page', 1); - $core->sauvePreferencesUtilisateur(); - } - - public static function motdepasseOublie($args, &$x) - { - self::form('recupMotdepasse', 'Mot de passe oublié ?', commonUrl::motdepasseOublie($args), __('Recevoir mon mot de passe par e-mail')); - } - - public static function mesParametres($args, &$x) - { - self::form('sauveMesParametres', 'Mes paramètres', commonUrl::mesParametres($args), false); - } - - public static function sauveMesParametres($args, &$x) - { - global $core; - $dao = new commonDAOUtilisateur($core->con); - $dao->changeParametres($core->user->utilisateur_id, $_POST['lang'], $_POST['login']); - $x->addRedirection(); - } - - public static function recupMotdepasse($args, &$x) - { - global $core; - $dao = new commonDAOUtilisateur($core->con); - $utilisateur = $dao->selectByEmail($_POST['email']); - - if (!is_null($utilisateur) && $utilisateur->enabled) { - $mail = new cubeMail(); - $mail->charset = 'UTF-8'; - $mail->from = FROM_NAME . '<' . FROM_EMAIL . '>'; - $mail->bcc = MAIL_BCC; - $mail->subject = '[' . EMAIL_SUBJECT . '] ' . __('Récupération de vos identifiants'); - $mail->to = $utilisateur->prenom . ' ' . $utilisateur->nom . '<' . $utilisateur->email . '>'; - $body = __('Bonjour,') . "\r\n\r\n"; - $body .= ASK_IDENT . "\r\n"; - $body .= __('Voici toutes les informations vous permettant de vous y connecter à nouveau :') . "\r\n\r\n"; - $body .= __('Adresse') . ' : https://' . $_SERVER['HTTP_HOST'] . '/' . "\r\n"; - $body .= __('Identifiant') . ' : ' . $utilisateur->email . "\r\n"; - $body .= __('Mot de passe') . ' : ' . $utilisateur->password . "\r\n\r\n"; - $body .= __('Cordialement,') . "\r\n"; - $body .= TEAM_NAME; - $mail->body = $body; - $ok = $mail->send(); - $message = $ok ? __('Vos identifiants vous ont été envoyé par e-mail') : __("Une erreur s'est produite lors de l'envoi de vos identifiants"); - } else { - $message = __('Cet e-mail ne correspond à aucun utilisateur du système'); - } - $x->addAlert($message); - $x->addClosePopup(); - } - - public static function changeMotdepasse($args, &$x) - { - self::form('sauveMotdepasse', 'Changer mon mot de passe', commonUrl::changeMotdepasse(), __('Enregistrer mon nouveau mot de passe')); - } - - public static function sauveMotdepasse($args, &$x) - { - global $core; - - $ok = true; - if ($_POST['actuel'] != $core->user->password) { - $x->addError('actuel', ''); - $ok = false; - } else { - $x->addOk('actuel'); - } - - if (strlen($_POST['nouveau']) > 10 || strlen($_POST['nouveau']) < 6 || $_POST['nouveau'] != $_POST['confirmation']) { - $x->addError('nouveau', ''); - $x->addError('confirmation', ''); - $ok = false; - } else { - $x->addOk('nouveau'); - $x->addOk('confirmation'); - } - - if ($ok) { - $dao = new commonDAOUtilisateur($core->con); - $dao->changeMotdepasse($core->user->utilisateur_id, $_POST['nouveau']); - - $_SESSION['user_password'] = $_POST['password']; - $x->addClosePopup(); - $x->addAlert(__('Votre mot de passe a été modifié')); - } - } - - // public static function connectAs($args, &$x) { - // global $core; - // $dao = new commonDAOUtilisateur($core->con); - // $utilisateur = $dao->selectById($args[1]); - // - // $_SESSION['user_email'] = $utilisateur->email; - // $_SESSION['user_password'] = $utilisateur->password; - // - // $x->addRedirection(SITE_PATH); - // } - - public static function sortFichiers($args, &$x) - { - commonAjax::sort('fichiers', $args[1]); - $x->addContent('listeFichiers', commonUrl::listeFichiers()); - } - - public static function pageFichiers($args, &$x) - { - commonAjax::page('fichiers', $args[1]); - $x->addContent('listeFichiers', commonUrl::listeFichiers()); - } - - public static function parPageFichiers($args, &$x) - { - commonAjax::parPage('fichiers', $_POST['par_page']); - $x->addContent('listeFichiers', commonUrl::listeFichiers()); - } - - public static function searchFichiers($args, &$x) - { - $x->addContent('listeFichiers', commonUrl::listeFichiers()); - } - - public static function refreshFichiers($args, &$x) - { - $x->addContent('listeFichiers', commonUrl::listeFichiers()); - } - - public static function supprimeFichier($args, &$x) - { - global $core; - - array_shift($args); - $path = implode('/', $args); - $entreprise = array_shift($args); - commonDroits::telecharger($entreprise); - - $dao = new commonDAOFichier($core->con); - $dao->supprime($path); - $x->addContent('listeFichiers', commonUrl::listeFichiers()); - } - - public static function formDashboard($args, &$x) - { - commonAjax::form('saveDashboard', __('Ajouter un élément au dashboard'), commonUrl::formDashboard($args)); - } - - public static function saveDashboard($args, &$x) - { - global $core; - - $c = $core->con->openCursor('dashboard'); - $c->site = MODE; - $c->nom = $_POST['nom']; - if ($_POST['dashboard_id'] == 'new') { - $c->rubrique = $_POST['rubrique']; - $c->equipier = $core->user->utilisateur_id; - $c->settings = serialize($core->user->getSettings($_POST['rubrique'])); - $r = $core->con->select('SELECT MAX(dashboard_id) AS dashboard_id FROM dashboard'); - $c->dashboard_id = $r->dashboard_id + 1; - $c->insert(); - } else { - $c->update('WHERE dashboard_id=\'' . $_POST['dashboard_id'] . '\''); - } - $x->addRedirection(SITE_PATH); - } - - public static function pageDashboard($args, &$x) - { - $settings = self::getDashboardSettings($args[1]); - $settings['page'] = $args[2]; - $r = self::saveDashboardSettings($args[1], $settings); - $x->addContent('dashboard_' . $args[1], commonUrl::displayDashboard($r)); - } - - public static function parPageDashboard($args, &$x) - { - $settings = self::getDashboardSettings($args[1]); - $settings['par_page'] = $_POST['par_page']; - $settings['page'] = 1; - $r = self::saveDashboardSettings($args[1], $settings); - $x->addContent('dashboard_' . $args[1], commonUrl::displayDashboard($r)); - } - - public static function sortDashboard($args, &$x) - { - $settings = self::getDashboardSettings($args[1]); - if ($settings['orderby'] == $args[2]) { - $settings['sens'] = ($settings['sens'] == 'ASC') ? 'DESC' : 'ASC'; - } else { - $settings['orderby'] = $args[2]; - $settings['sens'] = 'ASC'; - } - $r = self::saveDashboardSettings($args[1], $settings); - $x->addContent('dashboard_' . $args[1], commonUrl::displayDashboard($r)); - } - - public static function saveDashboardSettings($dashboard, $settings) - { - global $core; - - $settings['page'] = $settings['page'] ? $settings['page'] : 1; - - if ($settings['par_page'] > 0) { - $settings['limit'] = array(($settings['page'] - 1) * $settings['par_page'], $settings['par_page']); - } else { - $settings['limit'] = null; - } - - $c = $core->con->openCursor('dashboard'); - $c->settings = serialize($settings); - $c->update('WHERE dashboard_id=' . $dashboard); - return $core->con->select('SELECT * FROM dashboard WHERE dashboard_id=\'' . $core->con->escape($dashboard) . '\''); - } - - public static function getDashboardSettings($dashboard) - { - global $core; - $r = $core->con->select('SELECT * FROM dashboard WHERE dashboard_id=\'' . $core->con->escape($dashboard) . '\''); - return unserialize($r->settings); - } - - public static function delDashboard($args, &$x) - { - global $core; - $r = $core->con->execute('DELETE FROM dashboard WHERE dashboard_id=\'' . $core->con->escape($args[1]) . '\' AND equipier=\'' . $core->user->utilisateur_id . '\''); - $x->addReplace('dashboard_' . $args[1], ''); - } - - public static function reloadDashboards($args, &$x) - { - $x->addContent('dash', commonUrl::listeDashboard(array())); - } - - public static function orderDashboards($args, &$x) - { - global $core; - $c = $core->con->openCursor('dashboard'); - $i = 1; - foreach ($_GET['dashboard'] as $id) { - $c->sort = $i; - $c->update('WHERE dashboard_id=\'' . $core->con->escape($id) . '\''); - $i++; - } - } - - public static function toggleDashboard($args, &$x) - { - global $core; - - $r = $core->con->select('SELECT state FROM dashboard WHERE dashboard_id=\'' . $core->con->escape($args[1]) . '\''); - $new = ($r->state == '1') ? '0' : '1'; - - $c = $core->con->openCursor('dashboard'); - $c->state = $new; - $c->update('WHERE dashboard_id=\'' . $core->con->escape($args[1]) . '\''); - } - - public static function syncftp($args, &$x) - { - set_time_limit(0); - commonDroits::min(5); - $u = parse_url('ftp://' . ltrim($_POST['dest'], '/')); - if (!isset($u['port'])) { - $u['port'] = '21'; - } - - $commandes = array( - 'set ftp:ssl-allow false', - 'set net:reconnect-interval-base 5', - 'set net:max-retries 2', - 'set ftp:passive-mode ' . $_POST['mode'], - 'mkdir -p ' . $u['path'], - 'cd ' . $u['path'], - 'lcd ' . $_POST['source'], - 'mirror -Rve --parallel=5' - ); - - //$lftp->setManualArg( . '> mirror -Rv ' . $package); - - $lftp = new CubeIT_CommandLine('lftp'); - $lftp->setArg('u', $u['user'] . ',' . $u['pass']); - $lftp->setArg('p', $u['port']); - $lftp->setArg('e', implode(';', $commandes)); - $lftp->setArg(null, $u['host']); - $lftp->execute(); - $lftp->debug(); - - $x->addValue('res', utf8_encode($lftp->output)); - } - - public static function createGitRepos($args, &$x) - { - commonDroits::min(0.5); - $repos = $_POST['repos'] . '.git'; - $dir = "/mnt/sshfs/batman/home/git/repositories/$repos"; - `git init --bare $dir`; - `ln -s /home/git/.gitolite/hooks/common/post-receive $dir/hooks/post-receive`; - $x->addContent('res', 'Dépot crée :
git clone git@git.cubedesigners.com:' . $repos . '
'); - } - - public static function createDevSpace($args, &$x) - { - commonDroits::min(1); - global $core; - - $domain = $_POST['domain']; - $svn = $_POST['svn']; - $user = $_POST['user']; - $zend = $_POST['zend']; - if (!$user) { - $user = $domain; - } - - $domain = cubeText::str2URL($domain); - $user = cubeText::str2URL($user); - $svn = cubeText::str2URL($svn); - $password = CubeIT_Crypt::generateRandomString(10); - $zend = cubeText::str2URL($zend); - $zend = cubeText::ucfirst($zend); - - $body = "Adresse : https://$domain.dev1.cubedesigners.com + public static function form($action, $titre, $form, $bouton = null, $cols = 2, $class = '', $extra = '', $return = false) + { + global $core; + if ($class != '') { + $class = ' ' . $class; + } + $bouton = is_null($bouton) ? __('Enregister') : $bouton; + $colspan = $cols > 2 ? ' colspan="' . ($cols - 1) . '"' : ''; + $res = commonPage::bh(); + $res .= '
'; + $res .= ''; + $res .= '

' . $titre . '

'; + $res .= $form; + if ($bouton) { + $res .= ''; + } + $res .= '
' . cubeMedia::image(IMG . '/close.png') . '
' . $core->typo->BoutonOK($bouton) . '
'; + $res .= $extra; + $res .= '
'; + $res .= commonPage::bf(); + + if (!$return) { + echo $res; + exit; + } + return $res; + } + + public static function page($liste, $page) + { + global $core; + $core->user->changeSettings($liste, 'page', $page); + $core->sauvePreferencesUtilisateur(); + } + + public static function parPage($liste, $nb) + { + global $core; + $core->user->changeSettings($liste, 'par_page', $nb); + $core->user->changeSettings($liste, 'page', 1); + $core->sauvePreferencesUtilisateur(); + } + + public static function sort($liste, $orderby) + { + global $core; + $settings = $core->user->getSettings($liste); + if ($orderby == 'facture_id') { + $orderby = 'CAST(facture_id AS SIGNED)'; + } + + if ($settings['orderby'] == $orderby) { + $sens = ($settings['sens'] == 'ASC') ? 'DESC' : 'ASC'; + $core->user->changeSettings($liste, 'orderby', $orderby); + $core->user->changeSettings($liste, 'sens', $sens); + } else { + $core->user->changeSettings($liste, 'orderby', $orderby); + $core->user->changeSettings($liste, 'sens', 'ASC'); + } + $core->sauvePreferencesUtilisateur(); + } + + public static function filtre($liste, $data = null) + { + global $core; + $core->user->changeSettings($liste, 'filtres', $data); + $core->user->changeSettings($liste, 'page', 1); + $core->sauvePreferencesUtilisateur(); + } + + public static function motdepasseOublie($args, &$x) + { + self::form('recupMotdepasse', 'Mot de passe oublié ?', commonUrl::motdepasseOublie($args), __('Recevoir mon mot de passe par e-mail')); + } + + public static function mesParametres($args, &$x) + { + self::form('sauveMesParametres', 'Mes paramètres', commonUrl::mesParametres($args), false); + } + + public static function sauveMesParametres($args, &$x) + { + global $core; + $dao = new commonDAOUtilisateur($core->con); + $dao->changeParametres($core->user->utilisateur_id, $_POST['lang'], $_POST['login']); + $x->addRedirection(); + } + + public static function recupMotdepasse($args, &$x) + { + global $core; + $dao = new commonDAOUtilisateur($core->con); + $utilisateur = $dao->selectByEmail($_POST['email']); + + if (!is_null($utilisateur) && $utilisateur->enabled) { + $mail = new cubeMail(); + $mail->charset = 'UTF-8'; + $mail->from = FROM_NAME . '<' . FROM_EMAIL . '>'; + $mail->bcc = MAIL_BCC; + $mail->subject = '[' . EMAIL_SUBJECT . '] ' . __('Récupération de vos identifiants'); + $mail->to = $utilisateur->prenom . ' ' . $utilisateur->nom . '<' . $utilisateur->email . '>'; + $body = __('Bonjour,') . "\r\n\r\n"; + $body .= ASK_IDENT . "\r\n"; + $body .= __('Voici toutes les informations vous permettant de vous y connecter à nouveau :') . "\r\n\r\n"; + $body .= __('Adresse') . ' : https://' . $_SERVER['HTTP_HOST'] . '/' . "\r\n"; + $body .= __('Identifiant') . ' : ' . $utilisateur->email . "\r\n"; + $body .= __('Mot de passe') . ' : ' . $utilisateur->password . "\r\n\r\n"; + $body .= __('Cordialement,') . "\r\n"; + $body .= TEAM_NAME; + $mail->body = $body; + $ok = $mail->send(); + $message = $ok ? __('Vos identifiants vous ont été envoyé par e-mail') : __("Une erreur s'est produite lors de l'envoi de vos identifiants"); + } else { + $message = __('Cet e-mail ne correspond à aucun utilisateur du système'); + } + $x->addAlert($message); + $x->addClosePopup(); + } + + public static function changeMotdepasse($args, &$x) + { + self::form('sauveMotdepasse', 'Changer mon mot de passe', commonUrl::changeMotdepasse(), __('Enregistrer mon nouveau mot de passe')); + } + + public static function sauveMotdepasse($args, &$x) + { + global $core; + + $ok = true; + if ($_POST['actuel'] != $core->user->password) { + $x->addError('actuel', ''); + $ok = false; + } else { + $x->addOk('actuel'); + } + + if (strlen($_POST['nouveau']) > 10 || strlen($_POST['nouveau']) < 6 || $_POST['nouveau'] != $_POST['confirmation']) { + $x->addError('nouveau', ''); + $x->addError('confirmation', ''); + $ok = false; + } else { + $x->addOk('nouveau'); + $x->addOk('confirmation'); + } + + if ($ok) { + $dao = new commonDAOUtilisateur($core->con); + $dao->changeMotdepasse($core->user->utilisateur_id, $_POST['nouveau']); + + $_SESSION['user_password'] = $_POST['password']; + $x->addClosePopup(); + $x->addAlert(__('Votre mot de passe a été modifié')); + } + } + + // public static function connectAs($args, &$x) { + // global $core; + // $dao = new commonDAOUtilisateur($core->con); + // $utilisateur = $dao->selectById($args[1]); + // + // $_SESSION['user_email'] = $utilisateur->email; + // $_SESSION['user_password'] = $utilisateur->password; + // + // $x->addRedirection(SITE_PATH); + // } + + public static function sortFichiers($args, &$x) + { + commonAjax::sort('fichiers', $args[1]); + $x->addContent('listeFichiers', commonUrl::listeFichiers()); + } + + public static function pageFichiers($args, &$x) + { + commonAjax::page('fichiers', $args[1]); + $x->addContent('listeFichiers', commonUrl::listeFichiers()); + } + + public static function parPageFichiers($args, &$x) + { + commonAjax::parPage('fichiers', $_POST['par_page']); + $x->addContent('listeFichiers', commonUrl::listeFichiers()); + } + + public static function searchFichiers($args, &$x) + { + $x->addContent('listeFichiers', commonUrl::listeFichiers()); + } + + public static function refreshFichiers($args, &$x) + { + $x->addContent('listeFichiers', commonUrl::listeFichiers()); + } + + public static function supprimeFichier($args, &$x) + { + global $core; + + array_shift($args); + $path = implode('/', $args); + $entreprise = array_shift($args); + commonDroits::telecharger($entreprise); + + $dao = new commonDAOFichier($core->con); + $dao->supprime($path); + $x->addContent('listeFichiers', commonUrl::listeFichiers()); + } + + public static function formDashboard($args, &$x) + { + commonAjax::form('saveDashboard', __('Ajouter un élément au dashboard'), commonUrl::formDashboard($args)); + } + + public static function saveDashboard($args, &$x) + { + global $core; + + $c = $core->con->openCursor('dashboard'); + $c->site = MODE; + $c->nom = $_POST['nom']; + if ($_POST['dashboard_id'] == 'new') { + $c->rubrique = $_POST['rubrique']; + $c->equipier = $core->user->utilisateur_id; + $c->settings = serialize($core->user->getSettings($_POST['rubrique'])); + $r = $core->con->select('SELECT MAX(dashboard_id) AS dashboard_id FROM dashboard'); + $c->dashboard_id = $r->dashboard_id + 1; + $c->insert(); + } else { + $c->update('WHERE dashboard_id=\'' . $_POST['dashboard_id'] . '\''); + } + $x->addRedirection(SITE_PATH); + } + + public static function pageDashboard($args, &$x) + { + $settings = self::getDashboardSettings($args[1]); + $settings['page'] = $args[2]; + $r = self::saveDashboardSettings($args[1], $settings); + $x->addContent('dashboard_' . $args[1], commonUrl::displayDashboard($r)); + } + + public static function parPageDashboard($args, &$x) + { + $settings = self::getDashboardSettings($args[1]); + $settings['par_page'] = $_POST['par_page']; + $settings['page'] = 1; + $r = self::saveDashboardSettings($args[1], $settings); + $x->addContent('dashboard_' . $args[1], commonUrl::displayDashboard($r)); + } + + public static function sortDashboard($args, &$x) + { + $settings = self::getDashboardSettings($args[1]); + if ($settings['orderby'] == $args[2]) { + $settings['sens'] = ($settings['sens'] == 'ASC') ? 'DESC' : 'ASC'; + } else { + $settings['orderby'] = $args[2]; + $settings['sens'] = 'ASC'; + } + $r = self::saveDashboardSettings($args[1], $settings); + $x->addContent('dashboard_' . $args[1], commonUrl::displayDashboard($r)); + } + + public static function saveDashboardSettings($dashboard, $settings) + { + global $core; + + $settings['page'] = $settings['page'] ? $settings['page'] : 1; + + if ($settings['par_page'] > 0) { + $settings['limit'] = array(($settings['page'] - 1) * $settings['par_page'], $settings['par_page']); + } else { + $settings['limit'] = null; + } + + $c = $core->con->openCursor('dashboard'); + $c->settings = serialize($settings); + $c->update('WHERE dashboard_id=' . $dashboard); + return $core->con->select('SELECT * FROM dashboard WHERE dashboard_id=\'' . $core->con->escape($dashboard) . '\''); + } + + public static function getDashboardSettings($dashboard) + { + global $core; + $r = $core->con->select('SELECT * FROM dashboard WHERE dashboard_id=\'' . $core->con->escape($dashboard) . '\''); + return unserialize($r->settings); + } + + public static function delDashboard($args, &$x) + { + global $core; + $r = $core->con->execute('DELETE FROM dashboard WHERE dashboard_id=\'' . $core->con->escape($args[1]) . '\' AND equipier=\'' . $core->user->utilisateur_id . '\''); + $x->addReplace('dashboard_' . $args[1], ''); + } + + public static function reloadDashboards($args, &$x) + { + $x->addContent('dash', commonUrl::listeDashboard(array())); + } + + public static function orderDashboards($args, &$x) + { + global $core; + $c = $core->con->openCursor('dashboard'); + $i = 1; + foreach ($_GET['dashboard'] as $id) { + $c->sort = $i; + $c->update('WHERE dashboard_id=\'' . $core->con->escape($id) . '\''); + $i++; + } + } + + public static function toggleDashboard($args, &$x) + { + global $core; + + $r = $core->con->select('SELECT state FROM dashboard WHERE dashboard_id=\'' . $core->con->escape($args[1]) . '\''); + $new = ($r->state == '1') ? '0' : '1'; + + $c = $core->con->openCursor('dashboard'); + $c->state = $new; + $c->update('WHERE dashboard_id=\'' . $core->con->escape($args[1]) . '\''); + } + + public static function syncftp($args, &$x) + { + set_time_limit(0); + commonDroits::min(5); + $u = parse_url('ftp://' . ltrim($_POST['dest'], '/')); + if (!isset($u['port'])) { + $u['port'] = '21'; + } + + $commandes = array( + 'set ftp:ssl-allow false', + 'set net:reconnect-interval-base 5', + 'set net:max-retries 2', + 'set ftp:passive-mode ' . $_POST['mode'], + 'mkdir -p ' . $u['path'], + 'cd ' . $u['path'], + 'lcd ' . $_POST['source'], + 'mirror -Rve --parallel=5' + ); + + //$lftp->setManualArg( . '> mirror -Rv ' . $package); + + $lftp = new CubeIT_CommandLine('lftp'); + $lftp->setArg('u', $u['user'] . ',' . $u['pass']); + $lftp->setArg('p', $u['port']); + $lftp->setArg('e', implode(';', $commandes)); + $lftp->setArg(null, $u['host']); + $lftp->execute(); + $lftp->debug(); + + $x->addValue('res', utf8_encode($lftp->output)); + } + + public static function createGitRepos($args, &$x) + { + commonDroits::min(0.5); + $repos = $_POST['repos'] . '.git'; + $dir = "/mnt/sshfs/batman/home/git/repositories/$repos"; + `git init --bare $dir`; + `ln -s /home/git/.gitolite/hooks/common/post-receive $dir/hooks/post-receive`; + $x->addContent('res', 'Dépot crée :
git clone git@git.cubedesigners.com:' . $repos . '
'); + } + + public static function ttsBatch($args, &$x) + { + global $core; + + commonDroits::min(5); + $f = $_FILES['file']['tmp_name']; + $dir = CubeIT_Files::tmpdir(); + `unzip $f -d $dir`; + + $dao = new wsDAOBook($core->con); + + $files = CubeIT_Files::getRecursiveDirectoryIterator($dir); + $i = 0; + foreach ($files as $file) { + /** @var $file SplFileInfo */ + if (!$file->isFile() || $file->getExtension() != 'xlsx') { + continue; + } + + $base = $file->getBasename('.' . $file->getExtension()); + $e = explode('$', $base); + $id = array_pop($e); + + $f = $file->getRealPath(); + $f = addcslashes($f, "$ #!\"\'&)(*,;<>?[]\^`{}|~"); + $n = CubeIT_Text::str2URL($base) . '.xlsx'; + $dest = WS_BOOKS . '/working/' . $id . '/'; + $cmd = "mv $f $dest/$n"; + `$cmd`; + $settings = []; + if (isset($_POST['voice']) && $_POST['voice'] != '') { + $settings['audiodescriptionVoice'] = $_POST['voice']; + } + $settings['audiodescriptionTexts'] = $n; + $dao->setSettings($id, $settings); + $i++; + + } + + if ($i == 0) { + $res = __('Aucun fichier traité'); + } else { + $res = sprintf(__('%d fichiers ajoutés'), $i); + } + $x->addAlert($res); + } + + public static function createDevSpace($args, &$x) + { + commonDroits::min(1); + global $core; + + $domain = $_POST['domain']; + $svn = $_POST['svn']; + $user = $_POST['user']; + $zend = $_POST['zend']; + if (!$user) { + $user = $domain; + } + + $domain = cubeText::str2URL($domain); + $user = cubeText::str2URL($user); + $svn = cubeText::str2URL($svn); + $password = CubeIT_Crypt::generateRandomString(10); + $zend = cubeText::str2URL($zend); + $zend = cubeText::ucfirst($zend); + + $body = "Adresse : https://$domain.dev1.cubedesigners.com SSH : $domain.dev1.cubedesigners.com Nom d'utilisateur : $user @@ -404,148 +451,148 @@ Nom d'utilisateur : $user Nom de la base : $user Mot de passe : $password"; - if ($svn != '') { - $body .= "\n\nSVN : svn+ssh://svn@svn.cubedesigners.com/projects/$svn"; - } - - $users = array(); - if ($zend && isset($_POST['users']) && count($_POST['users'])) { - - foreach ($_POST['users'] as $u) { - $userpassword = CubeIT_Crypt::generateRandomString(10); - $users[$u] = $userpassword; - $b = $body . "\n\n"; - $b .= 'Admin : https://' . $domain . '.dev1.cubedesigners.com/admin/' . "\n"; - $b .= 'Nom d\'utilisateur : ' . $u . "\n"; - $b .= 'Mot de passe : ' . $userpassword . "\n"; - - $mail = new cubeMail(); - $mail->charset = 'UTF-8'; - $mail->from = 'extranet@cubedesigners.com'; - $mail->to = $u; - $mail->subject = 'Création de l\'espace de développement "' . $domain . '"'; - $mail->body = $b; - $mail->send(); - } - } else { - $mail = new cubeMail(); - $mail->charset = 'UTF-8'; - $mail->from = 'extranet@cubedesigners.com'; - $mail->to = $core->user->email; - $mail->subject = 'Création de l\'espace de développement "' . $domain . '"'; - $mail->body = $body; - $mail->send(); - } - - $args = "-l $user -o $domain -u $user -p $password"; - if ($zend) { - $args .= " -n $zend"; - } - if ($svn) { - $args .= " -d $svn"; - } - if (count($users)) { - $args .= ' -e ' . base64_encode(json_encode($users)); - } - - $cmd = "ssh root@clockwork.cubedesigners.com /usr/local/bin/tools/projectcreator/make.php $args"; - $out = `$cmd`; - $x->addDebug($cmd . ' : ' . $out); - $x->addAlert('Espace de développement crée. Vous allez recevoir un mail récapitulant les identifiants de l\'espace crée'); - } - - public static function postMailer($args, &$x) - { - $mail = new CubeIT_Mail_Mailjet(); - $mail->setFrom($_POST['from']); - $to = explode(',', $_POST['to']); - foreach ($to as $t) { - $t = trim($t); - if ($t == '') { - continue; - } - $mail->addTo($t); - } - $mail->setSubject($_POST['subject']); - $mail->setBodyHtmlFromZip($_FILES['src']['tmp_name'], '/mailer/' . time()); - $transport = new CubeIT_Mail_Transport_Mailjet("ca110b35f8735c223d69c9987c2ac47d", 'b289d0acb08e0fe56ce98ccf0dd1ed8b'); - $mail->send($transport); - } - - /** - * @param $args - * @param cubeAjax $x - * @throws PHPExcel_Exception - * @throws PHPExcel_Reader_Exception - */ - public static function importWSReferences($args, &$x) - { - global $core; - - new PHPExcel(); - - $e = explode('.', $_FILES['file']['name']); - $ext = mb_strtolower(array_pop($e)); + if ($svn != '') { + $body .= "\n\nSVN : svn+ssh://svn@svn.cubedesigners.com/projects/$svn"; + } + + $users = array(); + if ($zend && isset($_POST['users']) && count($_POST['users'])) { + + foreach ($_POST['users'] as $u) { + $userpassword = CubeIT_Crypt::generateRandomString(10); + $users[$u] = $userpassword; + $b = $body . "\n\n"; + $b .= 'Admin : https://' . $domain . '.dev1.cubedesigners.com/admin/' . "\n"; + $b .= 'Nom d\'utilisateur : ' . $u . "\n"; + $b .= 'Mot de passe : ' . $userpassword . "\n"; + + $mail = new cubeMail(); + $mail->charset = 'UTF-8'; + $mail->from = 'extranet@cubedesigners.com'; + $mail->to = $u; + $mail->subject = 'Création de l\'espace de développement "' . $domain . '"'; + $mail->body = $b; + $mail->send(); + } + } else { + $mail = new cubeMail(); + $mail->charset = 'UTF-8'; + $mail->from = 'extranet@cubedesigners.com'; + $mail->to = $core->user->email; + $mail->subject = 'Création de l\'espace de développement "' . $domain . '"'; + $mail->body = $body; + $mail->send(); + } + + $args = "-l $user -o $domain -u $user -p $password"; + if ($zend) { + $args .= " -n $zend"; + } + if ($svn) { + $args .= " -d $svn"; + } + if (count($users)) { + $args .= ' -e ' . base64_encode(json_encode($users)); + } + + $cmd = "ssh root@clockwork.cubedesigners.com /usr/local/bin/tools/projectcreator/make.php $args"; + $out = `$cmd`; + $x->addDebug($cmd . ' : ' . $out); + $x->addAlert('Espace de développement crée. Vous allez recevoir un mail récapitulant les identifiants de l\'espace crée'); + } + + public static function postMailer($args, &$x) + { + $mail = new CubeIT_Mail_Mailjet(); + $mail->setFrom($_POST['from']); + $to = explode(',', $_POST['to']); + foreach ($to as $t) { + $t = trim($t); + if ($t == '') { + continue; + } + $mail->addTo($t); + } + $mail->setSubject($_POST['subject']); + $mail->setBodyHtmlFromZip($_FILES['src']['tmp_name'], '/mailer/' . time()); + $transport = new CubeIT_Mail_Transport_Mailjet("ca110b35f8735c223d69c9987c2ac47d", 'b289d0acb08e0fe56ce98ccf0dd1ed8b'); + $mail->send($transport); + } + + /** + * @param $args + * @param cubeAjax $x + * @throws PHPExcel_Exception + * @throws PHPExcel_Reader_Exception + */ + public static function importWSReferences($args, &$x) + { + global $core; + + new PHPExcel(); + + $e = explode('.', $_FILES['file']['name']); + $ext = mb_strtolower(array_pop($e)); // $x->enableXML=false; // print_r($_FILES); // exit; - if ($ext == 'xlsx') { - $reader = new PHPExcel_Reader_Excel2007(); - } else if ($ext == 'csv') { - $reader = new PHPExcel_Reader_CSV(); - $reader->setDelimiter(";"); - } - - - $phpexcel = $reader->load($_FILES['file']['tmp_name']); - $sheet = $phpexcel->getSheet(0); - $maxRow = $sheet->getHighestRow(0); - - - for ($i = 1; $i <= $maxRow; $i++) { - $ref = trim($sheet->getCellByColumnAndRow(0, $i)); - $url = trim($sheet->getCellByColumnAndRow(1, $i)->getOldCalculatedValue()); - - if ($ref == '') { - $ref = trim($sheet->getCellByColumnAndRow(0, $i)->getFormattedValue()); - } - if ($url == '') { - $url = trim($sheet->getCellByColumnAndRow(1, $i)->getFormattedValue()); - } - - - if ($url == '' || $ref == '') { - continue; - } - - $fref = self::_formatWsReferenceRef($ref, $_POST['type']); - $furl = self::_formatWsReferenceUrl($url, $_POST['type']); - - $delete = "DELETE FROM wsref WHERE ref='" . $core->con->escape($fref) . "' AND type='" . $core->con->escape($_POST['type']) . "'"; - $core->con->execute($delete); - - $c = $core->con->openCursor('wsref'); - $c->type = $_POST['type']; - $c->ref = $fref; - $c->url = $furl; - $c->insert(); - } - } - - public static function _formatWsReferenceRef($ref, $type) - { - if ($type == '10doigts') { - if (stripos($ref, 'ic') === 0) { - return 'C' . substr($ref, 2); - } - } - return $ref; - } - - public static function _formatWsReferenceUrl($url, $type) - { - return $url; - } + if ($ext == 'xlsx') { + $reader = new PHPExcel_Reader_Excel2007(); + } else if ($ext == 'csv') { + $reader = new PHPExcel_Reader_CSV(); + $reader->setDelimiter(";"); + } + + + $phpexcel = $reader->load($_FILES['file']['tmp_name']); + $sheet = $phpexcel->getSheet(0); + $maxRow = $sheet->getHighestRow(0); + + + for ($i = 1; $i <= $maxRow; $i++) { + $ref = trim($sheet->getCellByColumnAndRow(0, $i)); + $url = trim($sheet->getCellByColumnAndRow(1, $i)->getOldCalculatedValue()); + + if ($ref == '') { + $ref = trim($sheet->getCellByColumnAndRow(0, $i)->getFormattedValue()); + } + if ($url == '') { + $url = trim($sheet->getCellByColumnAndRow(1, $i)->getFormattedValue()); + } + + + if ($url == '' || $ref == '') { + continue; + } + + $fref = self::_formatWsReferenceRef($ref, $_POST['type']); + $furl = self::_formatWsReferenceUrl($url, $_POST['type']); + + $delete = "DELETE FROM wsref WHERE ref='" . $core->con->escape($fref) . "' AND type='" . $core->con->escape($_POST['type']) . "'"; + $core->con->execute($delete); + + $c = $core->con->openCursor('wsref'); + $c->type = $_POST['type']; + $c->ref = $fref; + $c->url = $furl; + $c->insert(); + } + } + + public static function _formatWsReferenceRef($ref, $type) + { + if ($type == '10doigts') { + if (stripos($ref, 'ic') === 0) { + return 'C' . substr($ref, 2); + } + } + return $ref; + } + + public static function _formatWsReferenceUrl($url, $type) + { + return $url; + } } diff --git a/inc/commons/class.common.tools.php b/inc/commons/class.common.tools.php index 66786fec4..65448876a 100644 --- a/inc/commons/class.common.tools.php +++ b/inc/commons/class.common.tools.php @@ -3,309 +3,309 @@ class commonTools { - public static function hub($args) - { - global $core; - $args = cubePage::getArgs($args); - - $function = array_shift($args); - - if (!isset($_GET['light'])) { - echo commonPage::header($args); - } - - $cb = array('commonTools', $function); - if (is_callable($cb)) { - echo call_user_func($cb, $args); - } - - if (!isset($_GET['light'])) { - echo commonPage::footer(); - } - } - - public static function des() - { - global $core; - commonDroits::min(2); - - $ue = array_diff(cubeCountry::getUECountries(), array('FR')); - - $countries = "'" . implode("','", $ue) . "'"; - $limit = TIME - (3600 * 24 * 400); - - $limit = mktime(0, 0, 0, date('m', $limit), 1, date('y', $limit)); - - $tvanumbers = array(); - $r = $core->con->select('SELECT entreprise_id,tva_intra FROM entreprises'); - $filter = new CubeIT_Filter_VATEurope(); - while ($r->fetch()) { - $tvanumbers[$r->entreprise_id] = $filter->filter($r->tva_intra); - } - - $utilisateurs = array(); - $r = $core->con->select('SELECT utilisateur_id,entreprise FROM utilisateurs'); - while ($r->fetch()) { - $utilisateurs[$r->utilisateur_id] = $r->entreprise; - } - - $sql = 'SELECT * FROM factures_vue WHERE client_id IN (SELECT utilisateur_id FROM utilisateurs WHERE entreprise IN (SELECT entreprise_id FROM entreprises WHERE pays IN(' . $countries . '))) AND status > 0 AND date_creation>' . $limit . ' ORDER BY date_creation DESC'; - - $r = $core->con->select($sql); - $xls = new PHPExcel(); - $i = 0; - $data = array(); - while ($r->fetch()) { - $mois = date('Y-m', $r->date_creation); - if (!isset($data[$mois])) { - $data[$mois] = array(); - } - - $tva = $tvanumbers[$utilisateurs[$r->client_id]]; - if (!isset($data[$mois][$tva])) { - $data[$mois][$tva] = array('factures' => array(), 'montant' => 0, 'rs' => array()); - } - - $data[$mois][$tva]['montant'] += $r->total_ht; - $data[$mois][$tva]['factures'][] = $r->facture_id; - $data[$mois][$tva]['rs'][] = $r->client; - } - - - foreach ($data as $mois => $montants) { - if ($i == 0) { - $s = $xls->getActiveSheet(); - } else { - $s = $xls->createSheet(); - } - $s->setTitle($mois); - $s->getCell('A1')->setValue('# TVA'); - $s->getCell('B1')->setValue('Montant'); - $s->getCell('C1')->setValue('Nom(s)'); - $s->getCell('D1')->setValue('Facture(s)'); - $line = 2; - foreach ($montants as $tva => $d) { - $s->getCell('A' . $line)->setValue($tva); - $s->getCell('B' . $line)->setValue($d['montant']); - $s->getCell('C' . $line)->setValue(implode(',', array_unique($d['rs']))); - $s->getCell('D' . $line)->setValue(" " . implode(', ', $d['factures'])); - $line++; - } - $s->getColumnDimension('A')->setAutoSize(true); - $s->getColumnDimension('B')->setAutoSize(true); - $s->getColumnDimension('C')->setAutoSize(true); - $s->getColumnDimension('D')->setAutoSize(true); - $i++; - } - - header('Content-disposition: attachment; filename="des.xlsx'); - header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); - - ob_end_clean(); - $write = new PHPExcel_Writer_Excel2007($xls); - $write->save('php://output'); - exit; - - } - - public static function urlDecoder($args) - { - global $js; - $js[] = JS_PATH . '/urldecoder.js'; - - global $core; - $res = commonPage::barre(); - $res .= commonPage::tMain(); - $res .= commonPage::bh(); - $res .= '
'; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= '
' . __('Décoder une URL') . ' (' . __('de la forme') . ' : http%3A%2F%2Fwww )
Collez l\'url à décoder
Url décodée
'; - $res .= '
'; - $res .= ''; - $res .= commonPage::bf(); - $res .= commonPage::bMain(); - return $res; - } - - public static function html2php() - { - global $core; - - if (!isset($_POST['input'])) { - $r = ''; - } else { - $r = '
';
-			$lines = CubeIT_Text::explodeNewLines($_POST['input']);
-			foreach ($lines as $l) {
-				$l = trim($l);
-				if (!$l) {
-					continue;
-				}
-				$r .= "\$res.='" . addcslashes(htmlspecialchars($l), "'") . "';\n";
-			}
-
-			$r .= '
'; - } - - $res = commonPage::barre(); - $res .= commonPage::tMain(); - $res .= commonPage::bh(); - $res .= '
'; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= '
HTML2PHP
' . $r . '
' . $core->typo->BoutonOK(__('Générer le PHP')) . '
'; - $res .= '
'; - $res .= ''; - $res .= commonPage::bf(); - $res .= commonPage::bMain(); - return $res; - } - - public static function tubeMeta($args) - { - $url = $_GET['u']; - $hash = sha1($url); - - $web = '/tube/' . $hash . '/'; - $dir = ROOT . $web; - - header('Content-type: application/json'); - ob_end_clean(); - - $poster = $dir . 'video.jpg'; - if (file_exists($poster)) { - $dim = getimagesize($poster); - } - - $res = array('width' => $dim[0], - 'height' => $dim[1], - 'ratio' => round($dim[0] / $dim[1], 5)); - - echo json_encode($res); - exit; - } - - public static function url($args) - { - ob_end_clean(); - echo ''; - exit; - } - - public static function tube($args) - { - global $css, $js, $jsnomerge, $jsvar; - - $css = array(); - $js[] = JS_PATH . '/tube.js'; - $jsnomerge[] = JS_PATH . '/flashdetect.js'; - $js[] = JS_PATH . '/modernizr.js'; - - $url = $_GET['u']; - $hash = sha1($url); - - $onlyplayer = isset($_GET['onlyplayer']); - - if (!$onlyplayer) { - $web = '/tube/' . $hash . '/'; - $dir = ROOT . $web; - if (!file_exists($dir)) { - mkdir($dir, 0777, true); - $ext = files::getExtension($url); - if (preg_match('#^(\w+)(.*)$#', $ext, $matches)) { - $ext = $matches[1]; - } - $original = $dir . 'video.' . $ext; - copy($url, $original); - - require_once ROOT . '/inc/ws/Util/class.ws.tools.php'; - wsTools::encodeWebVideos($original); - } - } else { - $e = explode('/', $url); - array_pop($e); - $dir = $web = implode('/', $e); - } - - $jsvar['priority'] = isset($_GET['html5']) && $_GET['html5'] ? 'html5' : 'flash'; - - $loop = isset($_GET['loop']) ? $_GET['loop'] : 0; - $autoplay = isset($_GET['autoplay']) ? $_GET['autoplay'] : 0; - $controls = isset($_GET['controls']) ? $_GET['controls'] : 1; - $displayPoster = isset($_GET['poster']) ? $_GET['poster'] : 1; - $background = isset($_GET['background']) ? $_GET['background'] : '000000'; - $background = trim($background, '# '); - - $fv = array('video' => $url, - 'autoPlay' => $autoplay == 1, - 'controls' => $controls == 1, - 'loop' => $loop == 1, - 'background' => $background); - - if (file_exists($dir . 'video.jpg')) { - if ($displayPoster) { - $poster = $web . 'video.jpg'; - $fv['poster'] = $poster; - } - $dim = getimagesize($dir . 'video.jpg'); - } - - $res = ''; - - $video = '