article.php 7.37 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
2
<?php

Feu's avatar
Feu committed
3
/* Copyright 2006,2007
Ayolo's avatar
Ayolo committed
4
5
6
7
8
9
 * - Julien Etelain < julien at pmad dot net >
 *
 * Ce fichier fait partie du site de l'Association des Étudiants de
 * l'UTBM, http://ae.utbm.fr.
 *
 * This program is free software; you can redistribute it and/or
Ayolo's avatar
Ayolo committed
10
 * modify it under the terms of the GNU General Public License a
Ayolo's avatar
Ayolo committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

Skia's avatar
Skia committed
25
if ($_REQUEST['name'] == "services")
Krophil's avatar
Krophil committed
26
    header("Location: https://ae.utbm.fr/page/services/");
Skia's avatar
Skia committed
27

Ayolo's avatar
Ayolo committed
28
29
$topdir="./";

Feu's avatar
Feu committed
30
31
32
require_once($topdir. "include/site.inc.php");
require_once($topdir. "include/entities/page.inc.php");
require_once($topdir. "include/entities/asso.inc.php");
Ayolo's avatar
Ayolo committed
33

34
35
36
$conf['maxtoclevel']=4;
$conf['maxseclevel']=6;

Ayolo's avatar
Ayolo committed
37
38
39
40
41
42
43
44
45
46
47
48
49
$site = new site ();
$page = new page ($site->db,$site->dbrw);
$site->add_css("css/articles.css");
$site->add_css("css/doku.css");

if ( $site->user->is_valid()  && $site->user->is_in_group("moderateur_site") )
{
  $page->id_utilisateur = 0;
  $page->id_groupe = 8;
  $page->id_groupe_admin = 8;
  $page->droits_acces = 0x311;

  if ( $_REQUEST['action'] == "new" )
50
  {
51
    if ( !$_REQUEST["name"] || !preg_match("#^([a-z0-9\-_:\.]+)$#",$_REQUEST["name"]) )
52
53
54
      $Erreur = "Nom invalide";
    elseif ( !$_REQUEST["title"] || !$_REQUEST["texte"] )
      $Erreur = "Veuillez préciser un titre et/ou un contenu";
55
    elseif ( $page->load_by_pagename($_REQUEST["name"]) )
56
57
      $Erreur = "Cette page existe déjà";
    else
Ayolo's avatar
Ayolo committed
58
    {
59
60
      $page->set_rights($site->user,$_REQUEST['rights'],$_REQUEST['rights_id_group'],$_REQUEST['rights_id_group_admin']);
      $page->add($site->user, $_REQUEST["name"], $_REQUEST["title"], $_REQUEST['texte'], $_REQUEST['section']);
Ayolo's avatar
Ayolo committed
61
    }
62
63
64
65
66
67
68
  }

  if ( $_REQUEST['page'] == "new" || isset($Erreur) )
  {
    foreach ($site->tab_array as $entry)
      $sections[$entry[0]] = $entry[2];

69
    $site->start_page("accueil","Nouveau");
70
71
72
73
74
75
76
77
    $frm = new form("newarticle","article.php",true,"POST","Nouvelle page");
    if ( isset($Erreur) )
      $frm->error($Erreur);
    $frm->add_hidden("action","new");
    $frm->add_text_field("name","Nom",$_REQUEST["name"],true);
    $frm->add_text_field("title","Titre","",true);
    //$frm->add_entity_select("groupid","Groupe",$site->db,"group" );
    $frm->add_select_field("section","Section",$sections,"presentation");
78

79
80
81
    $frm->add_rights_field($page,false,$page->is_admin($site->user),"pages");
    $frm->add_dokuwiki_toolbar('texte');
    $frm->add_text_area("texte","Contenu","",80,20,true);
82

83
84
85
86
87
88
    $frm->add_submit("save","Ajouter");
    $site->add_contents($frm);
    $site->add_contents(new wikihelp());
    $site->end_page();
    exit();
  }
Ayolo's avatar
Ayolo committed
89
90
91

}

Feu's avatar
Feu committed
92
93
94
95
96
97
98
99
100
101
if ( isset($_REQUEST["name"]) && ereg("^activites-(.*)$",$_REQUEST["name"],$regs )) // LEGACY SUPPORT
{
  $asso = new asso($site->db);
  $asso->load_by_unix_name($regs[1]);
  if ( $asso->id > 0 )
  {
    header("Location: asso.php?id_asso=".$asso->id);
    exit();
  }
}
Ayolo's avatar
Ayolo committed
102

103
104
if ( ereg("^activites:(.*)$", $page->nom,$regs ))
{
jlaval's avatar
Debug    
jlaval committed
105
    echo 'Unix name :'.$regs[1].'\n';
106
107
108
109
110
111
112
113
114
  $asso = new asso($site->db);
  $asso->load_by_unix_name($regs[1]);
  if ( $asso->id > 0 )
  {
    header("Location: asso.php?id_asso=".$asso->id);
    exit();
  }
}

115
if ( isset($_REQUEST["name"]) )
Feu's avatar
Feu committed
116
117
{
  if ( $_REQUEST["name"]{0} == ":" )
118
    $page->load_by_pagename(substr($_REQUEST["name"],1));
Feu's avatar
Feu committed
119
  else
120
    $page->load_by_pagename($_REQUEST["name"]);
Feu's avatar
Feu committed
121
}
Ayolo's avatar
Ayolo committed
122
123
124

if ( !$page->is_valid() )
{
125
  $site->start_page("accueil","Erreur");
Ayolo's avatar
Ayolo committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139

  $err = new error("Page inconnue","Merci de vérifier le lien que vous avez emprunté");

  if ( $site->user->is_in_group("moderateur_site") )
    $err->set_toolbox(new toolbox(array("article.php?page=new&name=".
                                        $_REQUEST["name"] => "Creer la page")));

  $site->add_contents($err);
  $site->end_page();

  exit();
}

if ( !$page->is_right($site->user,DROIT_LECTURE) )
140
  $site->error_forbidden();
Ayolo's avatar
Ayolo committed
141
142
143
144
145
146
147

$section = "presentation";
if ( $page->section )
  $section = $page->section;

if( $section == "presentation" )
  $site->add_css("css/presentation.css");
mbriand's avatar
mbriand committed
148
149
150
151
152
153
154
155
  $tabs = array(
    array("presentation","article.php?name=presentation","Présentation"),
    array("services","article.php?name=presentation:services","Services quotidiens"),
    array("carteae","article.php?name=presentation:carteae","La carte AE"),
    array("siteae","article.php?name=presentation:siteae","Le site AE"),
    array("siteae","article.php?name=presentation:siteae","Activités et clubs"),
    array("siteae","article.php?name=presentation:siteae","Responsables des clubs"),
    );
Ayolo's avatar
Ayolo committed
156
157
158
159
160
161

if ( $page->is_right($site->user,DROIT_ECRITURE) )
{
  if ( $_REQUEST['action'] == "save" )
    {
      $page->set_rights($site->user,$_REQUEST['rights'],$_REQUEST['rights_id_group'],$_REQUEST['rights_id_group_admin']);
162
      $page->save( $site->user, $_REQUEST['title'], $_REQUEST['texte'], $_REQUEST['section'] );
Ayolo's avatar
Ayolo committed
163
164
165
166
167
168
169
170
171
172
173
174
      $section = $page->section;
    }
  if ( $_REQUEST['page'] == "edit" )
    {
      foreach ($site->tab_array as $entry)
        $sections[$entry[0]] = $entry[2];
      $site->start_page($section,"Edition :".$page->titre);
      $frm = new form("editarticle","article.php?name=".$page->nom,true,"POST","Edition : ".$page->nom);
      $frm->add_hidden("action","save");
      $frm->add_text_field("title","Titre",$page->titre,true);
      //$frm->add_entity_select("groupid","Groupe",$site->db,"group",$page->id_groupe );
      $frm->add_select_field("section","Section",$sections,$page->section);
175

Ayolo's avatar
Ayolo committed
176
      $frm->add_rights_field($page,false,$page->is_admin($site->user),"pages");
Feu's avatar
Feu committed
177
      $frm->add_dokuwiki_toolbar('texte');
Ayolo's avatar
Ayolo committed
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
      $frm->add_text_area("texte","Contenu",$page->texte,80,20,true);
      $frm->add_submit("save","Enregistrer");
      $site->add_contents($frm);
      $site->add_contents(new wikihelp());
      $site->end_page();
      exit();
    }
  $can_edit = true;
}
else
$can_edit = false;


if ( $page->nom == "services" /*|| $page->nom == "planning"*/ )
{
  $site->set_side_boxes("left",array("calendrier","connexion"));
  $site->add_box("calendrier",new calendar($site->db));
  $site->add_box("connexion", $site->get_connection_contents());
}

198

Ayolo's avatar
Ayolo committed
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
$site->start_page($section,$page->titre);
$cts = $page->get_contents();

if ( count($cts->wiki->index["childs"]) )
{
  function make_index($itm)
    {
      if ( is_null( $itm["title"] ) )
        $lst = new itemlist("Index");
      else
        $lst = new itemlist("<a href=\"#".$itm["ancre"]."\">".$itm["title"]."</a>");

      foreach($itm["childs"] as $sitm)
        {
          if (count($sitm["childs"]) )
Skia's avatar
Skia committed
214
            $lst->add(make_index($sitm));
Ayolo's avatar
Ayolo committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
          else
            $lst->add("<a href=\"#".$sitm["ancre"]."\">".$sitm["title"]."</a>");
        }
      return $lst;
    }

  $site->sides["left"] = array_merge (array("wikiindex"),$site->sides["left"]);
  $site->add_box("wikiindex", make_index($cts->wiki->index));
}

if ( $can_edit )
  $cts->set_toolbox(new toolbox(array("article.php?page=edit&name=".$page->nom=>"Editer","article.php?page=new"=>"Ajouter une page")));



$site->add_contents($cts);
$site->end_page();

?>