Пример #1
0
 /**
  *  Returns id of first found ecatalogue rubrique
  */
 public function FindFirstRubriqueId()
 {
     $r = lire_config('ecatalogue/branches');
     include_spip('formulaires/selecteur/generique_fonctions');
     $rubs_catalogue = picker_selected($r, 'rubrique');
     return isset($rubs_catalogue[0]) ? $rubs_catalogue[0] : false;
 }
Пример #2
0
function formulaires_editer_evenement_verifier_dist($id_evenement = 'new', $id_article = 0, $retour = '', $lier_trad = 0, $config_fonc = 'evenements_edit_config', $row = array(), $hidden = '')
{
    $erreurs = formulaires_editer_objet_verifier('evenement', $id_evenement, array('titre', 'date_debut', 'date_fin'));
    include_spip('inc/date_gestion');
    $horaire = _request('horaire') == 'non' ? false : true;
    if (!$erreurs['date_debut']) {
        $date_debut = verifier_corriger_date_saisie('debut', $horaire, $erreurs);
    }
    if (!$erreurs['date_fin']) {
        $date_fin = verifier_corriger_date_saisie('fin', $horaire, $erreurs);
    }
    if ($date_debut and $date_fin and $date_fin < $date_debut) {
        $erreurs['date_fin'] = _T('agenda:erreur_date_avant_apres');
    }
    include_spip('formulaires/selecteur/selecteur_fonctions');
    if (count($id = picker_selected(_request('parents_id'), 'article')) and $id = reset($id) and $id = sql_getfetsel('id_article', 'spip_articles', 'id_article=' . intval($id))) {
        // reinjecter dans id_parent
        set_request('id_parent', $id);
    }
    if (!($id_parent = intval(_request('id_parent')))) {
        $erreurs['id_parent'] = _T('agenda:erreur_article_manquant');
    } else {
        if (!autoriser('creerevenementdans', 'article', $id_parent)) {
            $erreurs['id_parent'] = _T('agenda:erreur_article_interdit');
        }
    }
    #if (!count($erreurs))
    #	$erreurs['message_erreur'] = 'ok?';
    return $erreurs;
}
/**
 *  Processing function
 */
function formulaires_ecatalogue_product_excel_download_traiter_dist()
{
    //require_once(_DIR_PLUGIN_ECATALOGUE.'classes/class.ProductExcel.php');
    $prd_ex = pdk_load_class('ProductExcel', 'classes');
    if (_request('download_rubriques')) {
        $prd_ex->DownloadRubriques = picker_selected(_request('download_rubriques'), 'rubrique');
    }
    if (_request('id_mot')) {
        $prd_ex->DownloadIdMot = _request('id_mot');
    }
    $prd_ex->OutputExcel();
}
 public function __construct()
 {
     include_spip('functions/pdk_common');
     include_spip('formulaires/selecteur/generique_fonctions');
     $this->product_mdl = pdk_load_class('ProductModel', 'classes/');
     $this->article_mdl = pdk_load_class('PdkArticleModel', 'classes/models');
     $this->rubrique_mdl = pdk_load_class('PdkRubriqueModel', 'classes/models');
     $this->rubrique_mdl2 = pdk_load_class('RubriqueModel', 'classes');
     $this->mot_lien_mdl = pdk_load_class('PdkMotLienModel', 'classes/models');
     require_once _DIR_PLUGIN_EXCEL . "pear/Spreadsheet/Excel/Writer.php";
     $this->UpdateStatus = lire_config('ecatalogue/excel_update_status');
     $this->DownloadRubriques = picker_selected(lire_config('ecatalogue/branches'), 'rubrique');
 }
Пример #5
0
function formulaires_ecatalogue_article_similar_traiter_dist($id_article)
{
    $result = array();
    $mdl = pdk_load_class('EcatArticleSimilarModel', 'classes');
    try {
        if ($selected_articles = _request('selected_articles')) {
            if (lire_config('ecatalogue/articles_select') == 'enhanced') {
                include_spip('formulaires/selecteur/generique_fonctions');
                $selected_articles = picker_selected(_request('selected_articles'), 'article');
            }
            if ($selected_articles) {
                $data = array('id_article' => $id_article);
                foreach ($selected_articles as $id_similar) {
                    if ($id_similar == $id_article) {
                        continue;
                    }
                    $data['id_similar'] = $id_similar;
                    $where = array('id_article=' . $data['id_article'], 'id_similar=' . $data['id_similar']);
                    // If such link doesn't exist yet, create it
                    if ($mdl->get_total($where) == 0) {
                        $mdl->insert($data);
                    }
                    if ($mdl->get_total($where) == 0) {
                        throw new Exception("Insert article similar fail!");
                    }
                }
            }
        }
        if ($id_similar_delete = _request('id_similar_delete')) {
            $where = array('id_article=' . $id_article, 'id_similar=' . $id_similar_delete);
            $mdl->delete($where);
            if ($mdl->get_total($where) != 0) {
                throw new Exception("Delete article similar fail!");
            }
        }
        $result['message_ok'] = _T('ecatalogue:form_saved');
    } catch (Exception $e) {
        $result['message_erreur'] = _T('ecatalogue:form_error');
    }
    set_request('id_similar_delete');
    return $result;
}
/**
 * Liste les éléments du sélecteur générique triés
 *
 * Les éléments sont triés par objets puis par identifiants
 *
 * @example
 *     L'entrée :
 *     'rubrique|3,rubrique|5,article|2'
 *     Retourne :
 *     array(
 *        0 => array('objet'=>'article', 'id_objet' => 2),
 *        1 => array('objet'=>'rubrique', 'id_objet' => 3),
 *        2 => array('objet'=>'rubrique', 'id_objet' => 5),
 *     )
 *
 * @param string $selected
 *     Liste des objets sélectionnés
 * @return array
 *     Liste des objets triés
**/
function picker_selected_par_objet($selected)
{
    $res = array();
    $liste = picker_selected($selected);
    // $liste : la sortie dans le désordre
    if (!$liste) {
        return $res;
    }
    foreach ($liste as $l) {
        if (!isset($res[$l['objet']])) {
            $res[$l['objet']] = array();
        }
        $res[$l['objet']][] = $l['id_objet'];
    }
    // $res est trié par objet, puis par identifiant
    ksort($res);
    foreach ($res as $objet => $ids) {
        sort($res[$objet]);
    }
    // on remet tout en file
    $liste = array();
    foreach ($res as $objet => $ids) {
        foreach ($ids as $id) {
            $liste[] = array('objet' => $objet, 'id_objet' => $id);
        }
    }
    return $liste;
}
Пример #7
0
function formulaires_ecatalogue_composite_traiter_dist($id_article)
{
    $result = array();
    $p_mdl = pdk_load_class('ProductModel', 'classes');
    $comp_mdl = pdk_load_class('CompositeArticleModel', 'classes');
    try {
        $data = $p_mdl->form_data_from_array($_REQUEST);
        if (!$data['is_separate']) {
            $data['is_separate'] = 0;
        } else {
            $data['is_separate'] = 1;
        }
        // This is needed for is_separate to be set in 0 when checkbox isn't checked
        if (!$data['is_composite']) {
            $data['is_composite'] = 0;
        } else {
            $data['is_composite'] = 1;
        }
        if (!$p_mdl->update_by_id($id_article, $data, true)) {
            throw new Exception("Product save fail!");
        }
        // Add components
        if ($selected_articles = _request('selected_articles')) {
            if (lire_config('ecatalogue/articles_select') == 'enhanced') {
                include_spip('formulaires/selecteur/generique_fonctions');
                $selected_articles = picker_selected(_request('selected_articles'), 'article');
            }
            if ($selected_articles) {
                $data = array('id_composite' => $id_article);
                foreach ($selected_articles as $id_component) {
                    if ($id_component == $id_article) {
                        continue;
                    }
                    $data['id_article'] = $id_component;
                    $where = array('id_composite=' . $data['id_composite'], 'id_article=' . $data['id_article']);
                    // If such link doesn't exist yet, create it
                    if ($comp_mdl->get_total($where) == 0) {
                        $comp_mdl->insert($data);
                    }
                    if ($comp_mdl->get_total($where) == 0) {
                        throw new Exception("Insert component article fail!");
                    }
                }
            }
        }
        // Delete components
        if ($id_component_delete = _request('id_component_delete')) {
            $where = array('id_composite=' . $id_article, 'id_article=' . $id_component_delete);
            $comp_mdl->delete($where);
            if ($comp_mdl->get_total($where) != 0) {
                throw new Exception("Delete component article fail!");
            }
        }
        // Update components
        if (_request('comp_arts') && is_array(_request('comp_arts'))) {
            foreach (_request('comp_arts') as $comp_art) {
                if ($comp_art['quantity'] > 0) {
                    $comp_mdl->update(array('id_composite=' . $id_article, 'id_article=' . intval($comp_art['id_article'])), array('quantity' => intval($comp_art['quantity'])));
                } else {
                    $comp_mdl->delete(array('id_composite=' . $id_article, 'id_article=' . intval($comp_art['id_article'])));
                }
            }
        }
        $result['message_ok'] = _T('ecatalogue:form_saved');
    } catch (Exception $e) {
        $result['message_erreur'] = _T('ecatalogue:form_error');
    }
    set_request('id_component_delete');
    return $result;
}