source: trunk/www/fr/includes/functions.inc @ 4546

Last change on this file since 4546 was 4546, checked in by matt, 17 years ago

Sync with the original version (use id instead of timestamp)

  • Property svn:eol-style set to native
File size: 9.4 KB
Line 
1<?php
2
3# $Id: functions.inc,v 1.4 2004/01/08 22:01:04 matt Exp $
4# Copyright (c) 2003, OpenDarwin
5
6######################################################################
7
8# variables and includes
9$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
10$PHP_SELF = $_SERVER['PHP_SELF'];
11include_once("$DOCUMENT_ROOT/includes/db.inc");
12$connect = mysql_pconnect($host, $user, $pass) or die("Can't connect to db!");
13mysql_select_db($db);
14
15######################################################################
16
17# create an RSS feed of the project news
18function create_rss() {
19  global $DOCUMENT_ROOT, $connect;
20
21  $query = "SELECT id, title, news FROM headlines ORDER BY id DESC LIMIT 10";
22  $result = mysql_query($query) or die("Error: $query.");
23  if(!$result) {
24    die("Error: $result.");
25  }
26
27  $open = fopen("$DOCUMENT_ROOT/dp_news.xml", "w+");
28  $rssdate = substr_replace(date("Y-m-d\TH:i:s0", time()),':', -2, 0);
29
30  $rss = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
31  $rss .= "<rss version=\"2.0\"\n";
32  $rss .= "  xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n";
33  $rss .= "  xmlns:sy=\"http://purl.org/rss/1.0/modules/syndication/\"\n";
34  $rss .= "  xmlns:admin=\"http://webns.net/mvcb/\"\n";
35  $rss .= "  xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n";
36  $rss .= "  xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n\n";
37
38  $rss .= "  <channel>\n";
39  $rss .= "    <title>DarwinPorts Project News</title>\n";
40  $rss .= "    <link>http://darwinports.opendarwin.org/</link>\n";
41  $rss .= "    <description>DarwinPorts Project News</description>\n";
42  $rss .= "    <dc:language>en-us</dc:language>\n";
43  $rss .= "    <dc:creator>Jim Mock (mij@opendarwin.org)</dc:creator>\n";
44  $rss .= "    <dc:rights>Copyright 2002-2003</dc:rights>\n";
45  $rss .= "    <dc:date>$rssdate</dc:date>\n";
46  $rss .= "    <admin:errorReportsTo rdf:resource\"mailto:mij@opendarwin.org\" />\n";
47
48  if(mysql_num_rows($result) > 0) {
49    while($row = mysql_fetch_object($result)) {
50      $rss .= "    <item>\n";
51      $rss .= "      <title>$row->title</title>\n";
52      $rss .= "      <link>http://darwinports.opendarwin.org/archives/$row->id.php</link>\n";
53
54      $desc_query = "SELECT SUBSTRING_INDEX(news, ' ', 26) FROM headlines WHERE id=$row->id";
55      $desc_result = mysql_query($desc_query);
56      $desc_row = mysql_fetch_row($desc_result);
57
58      $description = $desc_row[0];
59
60      $rss .= "      <description><![CDATA[$description...</p>]]></description>\n";
61      $rss .= "      <guid isPermaLink=\"true\">http://darwinports.opendarwin.org/archives/$row->id.php</guid>\n";
62      $rss .= "      <content:encoded><![CDATA[$row->news]]></content:encoded>\n";
63      $rss .= "    </item>\n";
64    }
65  }
66  $rss .= "  </channel>\n";
67  $rss .= "</rss>\n";
68
69  $write = fwrite($open, $rss);
70  $close = fclose($open);
71}
72
73######################################################################
74
75# print the project news
76function print_headlines() {
77  global $connect;
78
79  $query = "SELECT id, DATE_FORMAT(timestamp, '%e %b %Y, %l:%i %p') AS f_timestamp, title, news FROM headlines ORDER BY id DESC LIMIT 5";
80  $result = mysql_query($query) or die("Error: $query.");
81  if(!$result) {
82    die("Error: $result.");
83  }
84
85  if(mysql_num_rows($result) > 0) {
86    while($row = mysql_fetch_object($result)) {
87      echo "<h5 class=\"subhdr\">$row->title</h5>\n";
88      echo "<h6 class=\"date\">$row->f_timestamp</h6>\n";
89      echo "$row->news\n\n";
90    }
91  }
92  else {
93    echo "<p>Aucunes d&eacute;p&ecirc;ches &agrave; ce jour.</p>\n";
94  }
95}
96
97######################################################################
98
99# display a single headline
100function print_headline() {
101  global $connect;
102
103  $id = $_GET['id'];
104  $query = "SELECT id, DATE_FORMAT(timestamp, '%e %b %Y, %l:%i %p') AS f_timestamp, title, news FROM headlines WHERE id='$id'";
105  $result = mysql_query($query) or die("Error: $query.");
106  if(!$result) {
107    die("Error: $result.");
108  }
109
110  $row = mysql_fetch_object($result);
111  if($row) {
112    echo "<h5 class=\"subhdr\">$row->title</h5>\n";
113    echo "<h6 class=\"date\">$row->f_timestamp</h6>\n";
114    echo "$row->news\n\n";
115  }
116  else {
117    echo "<h2 class=\"hdr\">Erreur !</h2>\n";
118        echo "<p>La d&eacute;p&ecirc;che d&eacute;sir&eacute;e n'a put &ecirc;tre trouv&eacute;e. Soit elle ne figure pas dans la base de donn&eacute;es, soit une erreur est survenue.</p>\n";
119  }
120}
121
122######################################################################
123
124# print the form used to add project news
125function print_add_headline() {
126  global $PHP_SELF, $connect;
127
128  if(!$_POST['submit']) {
129    echo "<p>Utilisez le formulaire ci-dessous pour ajouter une d&eacute;p&ecirc;che li&eacute;e au projet.</p>\n\n";
130    echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
131    echo "<p>Title:&nbsp;&nbsp;<input type=\"text\" name=\"title\" size=\"40\" /></p>\n";
132    echo "<p>D&eacute;p&ecirc;che :</p>\n";
133    echo "<p><textarea name=\"news\" cols=\"70\" rows=\"20\"></textarea></p>\n";
134    echo "<p><input type=\"submit\" name=\"submit\" value=\"Soumettre\" /></p>\n";
135    echo "</form>\n\n";
136  }
137  else {
138    $title = $_POST['title'];
139    $news = $_POST['news'];
140    $errorList = array();
141    $count = 0;
142    if(!$title) {
143      $errorList[$count] = 'Invalid entry: Title';
144      $count++;
145    }
146    if(!$news) {
147      $errorList[$count] = 'Invalid entry: News';
148      $count++;
149    }
150    if(sizeof($errorList) == 0) {
151      $query = "INSERT INTO headlines (timestamp, title, news) VALUES (NOW(), '$title', '$news')";
152      $result = mysql_query($query) or die("Error: $query.");
153      if(!$result) {
154        die("Error: $result.");
155      }
156          echo "<p>La d&eacute;p&ecirc;che a &eacute;t&eacute; ajout&eacute;e. Vous pouvez <a href=\"list.php\">lister</a> toutes les d&eacute;p&ecirc;ches, <a href=\"add.php\">ajouter une autre d&eacute;p&ecirc;che</a>, ou <a href=\"/fr/\">retourner sur le site de DarwinPorts</a>.</p>\n\n";
157      create_rss();
158    }
159    else {
160      echo "<p>Les erreurs suivantes sont survenues :</p>\n\n";
161      echo "<ul>\n";
162      for($x=0; $x<sizeof($errorList); $x++) {
163        echo "<li>$errorList[$x]</li>\n";
164      }
165      echo "</ul>\n\n";
166    }
167  }
168}
169
170######################################################################
171
172# print the form used to edit project news
173function print_edit_headline($id) {
174  global $PHP_SELF, $connect;
175
176  if(!$_POST['submit']) {
177    $id = $_GET['id'];
178    $query = "SELECT title, news FROM headlines WHERE id='$id'";
179    $result = mysql_query($query) or die("Error: $query.");
180    if(!$result) {
181      die("Error: $result.");
182    }
183    if(mysql_num_rows($result) > 0) {
184      $row = mysql_fetch_object($result);
185      echo "<p>Utilisez le formulaire ci-dessous pour &eacute;diter les d&eacute;p&ecirc;ches du projet.</p>\n\n";
186      echo "<form action=\"$PHP_SELF?id=$id\" method=\"post\">\n";
187      echo "<p>Title:&nbsp;&nbsp;<input type=\"text\" name=\"title\" size=\"40\" value=\"$row->title\" /></p>\n";
188      echo "<p>D&eacute;p&ecirc;che :</p>\n";
189      echo "<p><textarea name=\"news\" cols=\"70\" rows=\"20\">";
190      echo htmlentities($row->news);
191      echo "</textarea></p>\n";
192      echo "<p><input type=\"submit\" name=\"submit\" value=\"&eacute;diter\" /></p>\n";
193      echo "</form>\n\n";
194    }
195    else {
196      echo "<p>La d&eacute;p&ecirc;che d&eacute;sir&eacute;e n'a put &ecirc;tre trouv&eacute;e. Soit elle ne figure pas dans la base de donn&eacute;es, soit une erreur est survenue. R&eacute;essayez.</p>\n\n";
197    }
198  }
199  else {
200    $title = $_POST['title'];
201    $news = $_POST['news'];
202    $errorList = array();
203    $count = 0;
204    if(!$title) {
205      $errorList[$count] = 'Invalid entry: Title';
206      $count++;
207    }
208    if(!$news) {
209      $errorList[$count] = 'Invalid entry: News';
210      $count++;
211    }
212    if(sizeof($errorList) == 0) {
213      $query = "UPDATE headlines SET title='$title', news='$news' WHERE id='$id'";
214      $result = mysql_query($query) or die("Error: $query.");
215
216      if(!$result) {
217        die("Error: $result.");
218      }
219      echo "<p>La d&eacute;p&ecirc;che a &eacute;t&eacute; mise &agrave; jour. Vous pouvez <a href=\"list.php\">lister</a> toutes les d&eacute;p&ecirc;ches, <a href=\"add.php\">ajouter une autre d&eacute;p&ecirc;che</a>, ou <a href=\"/fr/\">retourner sur le site de DarwinPorts</a>.</p>\n\n";
220      create_rss();
221    }
222    else {
223      echo "<p>Les erreurs suivantes sont survenues :</p>\n\n";
224      echo "<ul>\n";
225      for($x=0; $x<sizeof($errorList); $x++) {
226        echo "<li>$errorList[$x]</li>\n";
227      }
228      echo "</ul>\n\n";
229    }
230  }
231}
232
233######################################################################
234
235# print a list of all existing headlines
236function print_all_headlines() {
237  global $connect;
238
239  echo "<p>Voici ci-dessous la liste de toutes les d&eacute;p&ecirc;ches existantes. Elles peuvent &ecirc;tre visualis&eacute;es, &eacute;dit&eacute;es, ou effac&eacute;es depuis cette interface. Vous pouvez &eacute;galement <a href=\"add.php\">ajouter une d&eacute;p&ecirc;che</a>.</p>\n\n";
240
241  $query = "SELECT id, title, DATE_FORMAT(timestamp, '%e %b %Y, %l:%i %p') AS f_timestamp FROM headlines ORDER BY id DESC";
242  $result = mysql_query($query) or die("Error: $query.");
243  if(!$result) {
244    die("Error: $result.");
245  }
246  if(mysql_num_rows($result) > 0) {
247    while($row = mysql_fetch_object($result)) {
248      echo "<p><a href=\"/archives/$row->id.php\">$row->title</a><br />&nbsp&nbsp;$row->f_timestamp&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"edit.php?id=$row->id\">&eacute;diter</a></p>\n\n";
249    }
250  }
251  else {
252    echo "<p>Aucunes d&eacute;p&ecirc;ches disponibles.</p>\n\n";
253  }
254}
255
256?>
Note: See TracBrowser for help on using the repository browser.