dolibarr  9.0.0
external_rss.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Eric Seigne <erics@rycks.com>
3  * Copyright (C) 2003,2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
7  * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
8  * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
30 require '../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/rssparser.class.php';
33 
34 // Load translation files required by the page
35 $langs->load("admin");
36 
37 // Security check
38 if (!$user->admin) accessforbidden();
39 
40 $def = array();
41 $lastexternalrss=0;
42 $action=GETPOST('action','aZ09');
43 
44 
45 /*
46  * Actions
47  */
48 
49 // positionne la variable pour le nombre de rss externes
50 $sql ="SELECT ".$db->decrypt('name')." as name FROM ".MAIN_DB_PREFIX."const";
51 $sql.=" WHERE ".$db->decrypt('name')." LIKE 'EXTERNAL_RSS_URLRSS_%'";
52 //print $sql;
53 $result=$db->query($sql); // We can't use SELECT MAX() because EXTERNAL_RSS_URLRSS_10 is lower than EXTERNAL_RSS_URLRSS_9
54 if ($result)
55 {
56  while ($obj = $db->fetch_object($result))
57  {
58  preg_match('/([0-9]+)$/i',$obj->name,$reg);
59  if ($reg[1] && $reg[1] > $lastexternalrss) $lastexternalrss = $reg[1];
60  }
61 }
62 else
63 {
64  dol_print_error($db);
65 }
66 
67 if ($action == 'add' || GETPOST("modify"))
68 {
69  $external_rss_title = "external_rss_title_" . GETPOST("norss");
70  $external_rss_urlrss = "external_rss_urlrss_" . GETPOST("norss");
71 
72  if (! empty($_POST[$external_rss_urlrss]))
73  {
74  $boxlabel='(ExternalRSSInformations)';
75  //$external_rss_url = "external_rss_url_" . $_POST["norss"];
76 
77  $db->begin();
78 
79  if ($_POST["modify"])
80  {
81  // Supprime boite box_external_rss de definition des boites
82 /* $sql = "UPDATE ".MAIN_DB_PREFIX."boxes_def";
83  $sql.= " SET name = '".$boxlabel."'";
84  $sql.= " WHERE file ='box_external_rss.php' AND note like '".$_POST["norss"]." %'";
85 
86  $resql=$db->query($sql);
87  if (! $resql)
88  {
89  dol_print_error($db,"sql=$sql");
90  exit;
91  }
92 */
93  }
94  else
95  {
96  // Ajoute boite box_external_rss dans definition des boites
97  $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes_def (file, note)";
98  $sql.= " VALUES ('box_external_rss.php','".$db->escape(GETPOST("norss").' ('.GETPOST($external_rss_title)).")')";
99  if (! $db->query($sql))
100  {
101  dol_print_error($db);
102  $err++;
103  }
104  }
105 
106  $result1=dolibarr_set_const($db, "EXTERNAL_RSS_TITLE_" . GETPOST("norss"),GETPOST($external_rss_title),'chaine',0,'',$conf->entity);
107  if ($result1) $result2=dolibarr_set_const($db, "EXTERNAL_RSS_URLRSS_" . GETPOST("norss"),GETPOST($external_rss_urlrss),'chaine',0,'',$conf->entity);
108 
109  if ($result1 && $result2)
110  {
111  $db->commit();
112  header("Location: ".$_SERVER["PHP_SELF"]);
113  exit;
114  }
115  else
116  {
117  $db->rollback();
118  dol_print_error($db);
119  }
120  }
121 }
122 
123 if ($_POST["delete"])
124 {
125  if(GETPOST("norss"))
126  {
127  $db->begin();
128 
129  // Supprime boite box_external_rss de definition des boites
130  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."boxes_def";
131  $sql.= " WHERE file = 'box_external_rss.php' AND note LIKE '".$db->escape(GETPOST("norss"))." %'";
132 
133  $resql=$db->query($sql);
134  if ($resql)
135  {
136  $num = $db->num_rows($resql);
137  $i=0;
138  while ($i < $num)
139  {
140  $obj=$db->fetch_object($resql);
141 
142  $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes";
143  $sql.= " WHERE entity = ".$conf->entity;
144  $sql.= " AND box_id = ".$obj->rowid;
145  $resql=$db->query($sql);
146 
147  $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes_def";
148  $sql.= " WHERE rowid = ".$obj->rowid;
149  $resql=$db->query($sql);
150 
151  if (! $resql)
152  {
153  $db->rollback();
154  dol_print_error($db,"sql=".$sql);
155  exit;
156  }
157 
158  $i++;
159  }
160 
161  $db->commit();
162  }
163  else
164  {
165  $db->rollback();
166  dol_print_error($db,"sql=".$sql);
167  exit;
168  }
169 
170 
171  $result1=dolibarr_del_const($db,"EXTERNAL_RSS_TITLE_" . GETPOST("norss"),$conf->entity);
172  if ($result1) $result2=dolibarr_del_const($db,"EXTERNAL_RSS_URLRSS_" . GETPOST("norss"),$conf->entity);
173 
174  if ($result1 && $result2)
175  {
176  $db->commit();
177  header("Location: external_rss.php");
178  exit;
179  }
180  else
181  {
182  $db->rollback();
183  dol_print_error($db);
184  }
185  }
186 }
187 
188 
189 /*
190  * View
191  */
192 
193 llxHeader('',$langs->trans("ExternalRSSSetup"));
194 
195 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
196 print load_fiche_titre($langs->trans("ExternalRSSSetup"), $linkback, 'title_setup');
197 print '<br>';
198 
199 // Formulaire ajout
200 print '<form name="externalrssconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
201 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
202 
203 print '<table class="noborder" width="100%">';
204 print '<tr class="liste_titre">';
205 print '<td colspan="2">'.$langs->trans("NewRSS").'</td>';
206 print '<td>'.$langs->trans("Example").'</td>';
207 print '</tr>';
208 print '<tr class="impair">';
209 print '<td width="100">'.$langs->trans("Title").'</td>';
210 print '<td><input type="text" class="flat minwidth300" name="external_rss_title_'.($lastexternalrss+1).'" value=""></td>';
211 print '<td>'.$langs->trans('RSSUrlExample').'</td>';
212 print '</tr>';
213 
214 print '<tr class="pair">';
215 print '<td>'.$langs->trans('RSSUrl').'</td>';
216 print '<td><input type="text" class="flat minwidth300" name="external_rss_urlrss_'.($lastexternalrss+1).'" value=""></td>';
217 print '<td>http://news.google.com/news?ned=us&topic=h&output=rss<br>http://www.dolibarr.org/rss</td>';
218 print '</tr>';
219 print '</table>';
220 
221 print '<br><div class="center">';
222 print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
223 print '<input type="hidden" name="action" value="add">';
224 print '<input type="hidden" name="norss" value="'.($lastexternalrss+1).'">';
225 print '</div><br><br>';
226 
227 print '</form>';
228 
229 
230 $sql ="SELECT rowid, file, note FROM ".MAIN_DB_PREFIX."boxes_def";
231 $sql.=" WHERE file = 'box_external_rss.php'";
232 $sql.=" ORDER BY note";
233 
234 dol_syslog("select rss boxes", LOG_DEBUG);
235 $resql=$db->query($sql);
236 if ($resql)
237 {
238  $num =$db->num_rows($resql);
239  $i=0;
240 
241  while ($i < $num)
242  {
243  $obj = $db->fetch_object($resql);
244 
245  preg_match('/^([0-9]+)/i',$obj->note,$reg);
246  $idrss = $reg[1];
247  $keyrsstitle="EXTERNAL_RSS_TITLE_".$idrss;
248  $keyrssurl="EXTERNAL_RSS_URLRSS_".$idrss;
249  //print "x".$idrss;
250 
251  $rssparser=new RssParser($db);
252  $result = $rssparser->parser($conf->global->$keyrssurl, 5, 300, $conf->externalrss->dir_temp);
253 
254  print "<br>";
255  print "<form name=\"externalrssconfig\" action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\">";
256 
257  print '<table class="noborder" width="100%">';
258  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
259 
260  print "<tr class=\"liste_titre\">";
261  print "<td>".$langs->trans("RSS")." ".($i+1)."</td>";
262  print '<td align="right">';
263  print "<input type=\"submit\" class=\"button\" name=\"modify\" value=\"".$langs->trans("Modify")."\">";
264  print " &nbsp; ";
265  print "<input type=\"submit\" class=\"button\" name=\"delete\" value=\"".$langs->trans("Delete")."\">";
266  print "<input type=\"hidden\" name=\"norss\" value=\"".$idrss."\">";
267  print '</td>';
268  print "</tr>";
269 
270 
271  print '<tr class="oddeven">';
272  print "<td width=\"100px\">".$langs->trans("Title")."</td>";
273  print "<td><input type=\"text\" class=\"flat minwidth300\" name=\"external_rss_title_" . $idrss . "\" value=\"" . $conf->global->$keyrsstitle . "\"></td>";
274  print "</tr>";
275 
276 
277  print '<tr class="oddeven">';
278  print "<td>".$langs->trans("URL")."</td>";
279  print "<td><input type=\"text\" class=\"flat minwidth300\" name=\"external_rss_urlrss_" . $idrss . "\" value=\"" . $conf->global->$keyrssurl . "\"></td>";
280  print "</tr>";
281 
282 
283  print '<tr class="oddeven">';
284  print "<td>".$langs->trans("Status")."</td>";
285  print "<td>";
286  if ($result > 0 && empty($rss->error))
287  {
288  print '<font class="ok">'.$langs->trans("Online").'</div>';
289  }
290  else
291  {
292  print '<font class="error">'.$langs->trans("Offline");
293  $langs->load("errors");
294  if ($rssparser->error) print ' - '.$langs->trans($rssparser->error);
295  print '</div>';
296  }
297  print "</td>";
298  print "</tr>";
299 
300  // Logo
301  if ($result > 0 && empty($rss->error))
302  {
303 
304  print '<tr class="oddeven">';
305  print "<td>".$langs->trans("Logo")."</td>";
306  print '<td>';
307  $imageurl=$rssparser->getImageUrl();
308  $linkrss=$rssparser->getLink();
309  if (! preg_match('/^http/', $imageurl)) $imageurl=$linkrss.$imageurl;
310  if ($imageurl) print '<img height="32" src="'.$imageurl.'">';
311  else print $langs->trans("None");
312  print '</td>';
313  print "</tr>";
314  }
315 
316  print '</table>';
317 
318  print "</form>";
319 
320  $i++;
321  }
322 }
323 else
324 {
325  dol_print_error($db);
326 }
327 
328 // End of page
329 llxFooter();
330 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:510
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:435
llxHeader()
Empty header.
Definition: wrapper.php:44
Class to parse RSS files.