[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / ecrire / inc / preselectionner_parent_nouvel_objet.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2016 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13
14 if (!defined('_ECRIRE_INC_VERSION')) return;
15 if (!defined('_AUTO_SELECTION_RUBRIQUE'))
16 define('_AUTO_SELECTION_RUBRIQUE',false);
17
18
19 /**
20 * Preselectionner la rubrique lors de la creation
21 * desactive par defaut suite a remontee utilisateur mais activable par define
22 * ou surchargeable
23 *
24 * @param string $objet
25 * @param array $row
26 * @return string
27 */
28 function inc_preselectionner_parent_nouvel_objet_dist($objet, $row){
29 if (!_AUTO_SELECTION_RUBRIQUE)
30 return '';
31
32 if (!isset($row['id_rubrique']))
33 return '';
34
35 $id_rubrique = '';
36 if ($GLOBALS['connect_id_rubrique']){
37 // si admin restreint : sa rubrique
38 $id_rubrique = $GLOBALS['connect_id_rubrique'][0];
39 }
40 else {
41 // sinon la derniere rubrique cree
42 $row_rub = sql_fetsel("id_rubrique", "spip_rubriques", "", "", "id_rubrique DESC", "0,1");
43 $id_rubrique = $row_rub['id_rubrique'];
44 }
45 // si le choix ne convient pas, on cherche dans un secteur
46 if (!autoriser('creer'.$objet.'dans','rubrique',$id_rubrique)){
47 $id_rubrique = '';
48 // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
49 $res = sql_select("id_rubrique", "spip_rubriques", "id_parent=0");
50 while (!$id_rubrique AND $row_rub = sql_fetch($res)){
51 if (autoriser('creer'.$objet.'dans','rubrique',$row_rub['id_rubrique']))
52 $id_rubrique = $row_rub['id_rubrique'];
53 }
54 }
55 return $id_rubrique;
56
57 }