dolibarr  7.0.0-beta
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@capnetworks.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 $langs->load("admin");
35 
36 // Security check
37 if (!$user->admin) accessforbidden();
38 
39 $def = array();
40 $lastexternalrss=0;
41 $action=GETPOST('action','aZ09');
42 
43 
44 /*
45  * Actions
46  */
47 
48 // positionne la variable pour le nombre de rss externes
49 $sql ="SELECT ".$db->decrypt('name')." as name FROM ".MAIN_DB_PREFIX."const";
50 $sql.=" WHERE ".$db->decrypt('name')." LIKE 'EXTERNAL_RSS_URLRSS_%'";
51 //print $sql;
52 $result=$db->query($sql); // We can't use SELECT MAX() because EXTERNAL_RSS_URLRSS_10 is lower than EXTERNAL_RSS_URLRSS_9
53 if ($result)
54 {
55  while ($obj = $db->fetch_object($result))
56  {
57  preg_match('/([0-9]+)$/i',$obj->name,$reg);
58  if ($reg[1] && $reg[1] > $lastexternalrss) $lastexternalrss = $reg[1];
59  }
60 }
61 else
62 {
63  dol_print_error($db);
64 }
65 
66 if ($action == 'add' || GETPOST("modify"))
67 {
68  $external_rss_title = "external_rss_title_" . GETPOST("norss");
69  $external_rss_urlrss = "external_rss_urlrss_" . GETPOST("norss");
70 
71  if (! empty($_POST[$external_rss_urlrss]))
72  {
73  $boxlabel='(ExternalRSSInformations)';
74  //$external_rss_url = "external_rss_url_" . $_POST["norss"];
75 
76  $db->begin();
77 
78  if ($_POST["modify"])
79  {
80  // Supprime boite box_external_rss de definition des boites
81 /* $sql = "UPDATE ".MAIN_DB_PREFIX."boxes_def";
82  $sql.= " SET name = '".$boxlabel."'";
83  $sql.= " WHERE file ='box_external_rss.php' AND note like '".$_POST["norss"]." %'";
84 
85  $resql=$db->query($sql);
86  if (! $resql)
87  {
88  dol_print_error($db,"sql=$sql");
89  exit;
90  }
91 */
92  }
93  else
94  {
95  // Ajoute boite box_external_rss dans definition des boites
96  $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes_def (file, note)";
97  $sql.= " VALUES ('box_external_rss.php','".$db->escape(GETPOST("norss").' ('.GETPOST($external_rss_title)).")')";
98  if (! $db->query($sql))
99  {
100  dol_print_error($db);
101  $err++;
102  }
103  }
104 
105  $result1=dolibarr_set_const($db, "EXTERNAL_RSS_TITLE_" . GETPOST("norss"),GETPOST($external_rss_title),'chaine',0,'',$conf->entity);
106  if ($result1) $result2=dolibarr_set_const($db, "EXTERNAL_RSS_URLRSS_" . GETPOST("norss"),GETPOST($external_rss_urlrss),'chaine',0,'',$conf->entity);
107 
108  if ($result1 && $result2)
109  {
110  $db->commit();
111  header("Location: ".$_SERVER["PHP_SELF"]);
112  exit;
113  }
114  else
115  {
116  $db->rollback();
117  dol_print_error($db);
118  }
119  }
120 }
121 
122 if ($_POST["delete"])
123 {
124  if(GETPOST("norss"))
125  {
126  $db->begin();
127 
128  // Supprime boite box_external_rss de definition des boites
129  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."boxes_def";
130  $sql.= " WHERE file = 'box_external_rss.php' AND note LIKE '".$db->escape(GETPOST("norss"))." %'";
131 
132  $resql=$db->query($sql);
133  if ($resql)
134  {
135  $num = $db->num_rows($resql);
136  $i=0;
137  while ($i < $num)
138  {
139  $obj=$db->fetch_object($resql);
140 
141  $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes";
142  $sql.= " WHERE entity = ".$conf->entity;
143  $sql.= " AND box_id = ".$obj->rowid;
144  $resql=$db->query($sql);
145 
146  $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes_def";
147  $sql.= " WHERE rowid = ".$obj->rowid;
148  $resql=$db->query($sql);
149 
150  if (! $resql)
151  {
152  $db->rollback();
153  dol_print_error($db,"sql=".$sql);
154  exit;
155  }
156 
157  $i++;
158  }
159 
160  $db->commit();
161  }
162  else
163  {
164  $db->rollback();
165  dol_print_error($db,"sql=".$sql);
166  exit;
167  }
168 
169 
170  $result1=dolibarr_del_const($db,"EXTERNAL_RSS_TITLE_" . GETPOST("norss"),$conf->entity);
171  if ($result1) $result2=dolibarr_del_const($db,"EXTERNAL_RSS_URLRSS_" . GETPOST("norss"),$conf->entity);
172 
173  if ($result1 && $result2)
174  {
175  $db->commit();
176  header("Location: external_rss.php");
177  exit;
178  }
179  else
180  {
181  $db->rollback();
182  dol_print_error($db);
183  }
184  }
185 }
186 
187 
188 /*
189  * View
190  */
191 
192 llxHeader('',$langs->trans("ExternalRSSSetup"));
193 
194 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
195 print load_fiche_titre($langs->trans("ExternalRSSSetup"), $linkback, 'title_setup');
196 print '<br>';
197 
198 // Formulaire ajout
199 print '<form name="externalrssconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
200 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
201 
202 print '<table class="noborder" width="100%">';
203 print '<tr class="liste_titre">';
204 print '<td colspan="2">'.$langs->trans("NewRSS").'</td>';
205 print '<td>'.$langs->trans("Example").'</td>';
206 print '</tr>';
207 print '<tr class="impair">';
208 print '<td width="100">'.$langs->trans("Title").'</td>';
209 print '<td><input type="text" class="flat minwidth300" name="external_rss_title_'.($lastexternalrss+1).'" value=""></td>';
210 print '<td>'.$langs->trans('RSSUrlExample').'</td>';
211 print '</tr>';
212 
213 print '<tr class="pair">';
214 print '<td>'.$langs->trans('RSSUrl').'</td>';
215 print '<td><input type="text" class="flat minwidth300" name="external_rss_urlrss_'.($lastexternalrss+1).'" value=""></td>';
216 print '<td>http://news.google.com/news?ned=us&topic=h&output=rss<br>http://www.dolibarr.org/rss</td>';
217 print '</tr>';
218 print '</table>';
219 
220 print '<br><div class="center">';
221 print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
222 print '<input type="hidden" name="action" value="add">';
223 print '<input type="hidden" name="norss" value="'.($lastexternalrss+1).'">';
224 print '</div><br><br>';
225 
226 print '</form>';
227 
228 
229 $sql ="SELECT rowid, file, note FROM ".MAIN_DB_PREFIX."boxes_def";
230 $sql.=" WHERE file = 'box_external_rss.php'";
231 $sql.=" ORDER BY note";
232 
233 dol_syslog("select rss boxes", LOG_DEBUG);
234 $resql=$db->query($sql);
235 if ($resql)
236 {
237  $num =$db->num_rows($resql);
238  $i=0;
239 
240  while ($i < $num)
241  {
242  $obj = $db->fetch_object($resql);
243 
244  preg_match('/^([0-9]+)/i',$obj->note,$reg);
245  $idrss = $reg[1];
246  $keyrssurl="EXTERNAL_RSS_URLRSS_".$idrss;
247  $keyrsstitle="EXTERNAL_RSS_URLRSS_".$idrss;
248  //print "x".$idrss;
249 
250  $rssparser=new RssParser($db);
251  $result = $rssparser->parser($conf->global->$keyrssurl, 5, 300, $conf->externalrss->dir_temp);
252 
253  $var=true;
254 
255  print "<br>";
256  print "<form name=\"externalrssconfig\" action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\">";
257 
258  print '<table class="noborder" width="100%">';
259  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
260 
261  print "<tr class=\"liste_titre\">";
262  print "<td>".$langs->trans("RSS")." ".($i+1)."</td>";
263  print '<td align="right">';
264  print "<input type=\"submit\" class=\"button\" name=\"modify\" value=\"".$langs->trans("Modify")."\">";
265  print " &nbsp; ";
266  print "<input type=\"submit\" class=\"button\" name=\"delete\" value=\"".$langs->trans("Delete")."\">";
267  print "<input type=\"hidden\" name=\"norss\" value=\"".$idrss."\">";
268  print '</td>';
269  print "</tr>";
270 
271 
272  print '<tr class="oddeven">';
273  print "<td width=\"100px\">".$langs->trans("Title")."</td>";
274  print "<td><input type=\"text\" class=\"flat minwidth300\" name=\"external_rss_title_" . $idrss . "\" value=\"" . $conf->global->$keyrsstitle . "\"></td>";
275  print "</tr>";
276 
277 
278  print '<tr class="oddeven">';
279  print "<td>".$langs->trans("URL")."</td>";
280  print "<td><input type=\"text\" class=\"flat minwidth300\" name=\"external_rss_urlrss_" . $idrss . "\" value=\"" . $conf->global->$keyrssurl . "\"></td>";
281  print "</tr>";
282 
283 
284  print '<tr class="oddeven">';
285  print "<td>".$langs->trans("Status")."</td>";
286  print "<td>";
287  if ($result > 0 && empty($rss->error))
288  {
289  print '<font class="ok">'.$langs->trans("Online").'</div>';
290  }
291  else
292  {
293  print '<font class="error">'.$langs->trans("Offline");
294  $langs->load("errors");
295  if ($rssparser->error) print ' - '.$langs->trans($rssparser->error);
296  print '</div>';
297  }
298  print "</td>";
299  print "</tr>";
300 
301  // Logo
302  if ($result > 0 && empty($rss->error))
303  {
304 
305  print '<tr class="oddeven">';
306  print "<td>".$langs->trans("Logo")."</td>";
307  print '<td>';
308  $imageurl=$rssparser->getImageUrl();
309  $linkrss=$rssparser->getLink();
310  if (! preg_match('/^http/', $imageurl)) $imageurl=$linkrss.$imageurl;
311  if ($imageurl) print '<img height="32" src="'.$imageurl.'">';
312  else print $langs->trans("None");
313  print '</td>';
314  print "</tr>";
315  }
316 
317  print '</table>';
318 
319  print "</form>";
320 
321  $i++;
322  }
323 }
324 else
325 {
326  dol_print_error($db);
327 }
328 
329 
330 llxFooter();
331 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
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:485
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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'une constante dans la base de donnees.
Definition: admin.lib.php:410
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
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:1013
Class to parse RSS files.