move code up one directory
[atutor.git] / mods / _standard / rss_feeds / edit_feed.php
1 <?php   \r
2 /************************************************************************/\r
3 /* ATutor                                                                                                                               */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2002-2010                                              */\r
6 /* Inclusive Design Institute                                           */\r
7 /* http://atutor.ca                                                                                                             */\r
8 /*                                                                                                                                              */\r
9 /* This program is free software. You can redistribute it and/or        */\r
10 /* modify it under the terms of the GNU General Public License          */\r
11 /* as published by the Free Software Foundation.                        */\r
12 /************************************************************************/\r
13 // $Id$\r
14 \r
15 define('AT_INCLUDE_PATH', '../../../include/');\r
16 require(AT_INCLUDE_PATH . 'vitals.inc.php');\r
17 \r
18 admin_authenticate(AT_ADMIN_PRIV_RSS);\r
19 \r
20 $feed_id = intval($_GET['fid']);\r
21 $title_file = AT_CONTENT_DIR.'feeds/'.$feed_id.'_rss_title.cache';\r
22 \r
23 if (isset($_GET['submit'])) {\r
24         $missing_fields = array();\r
25         //check both fields are not empty\r
26         if (trim($_REQUEST['title']) == '') {\r
27                 $missing_fields[] = _AT('title');\r
28         }\r
29 \r
30 \r
31 \r
32         if (trim($_REQUEST['url']) == '') {\r
33                 $missing_fields[] = _AT('url');\r
34         }\r
35         if ($missing_fields) {\r
36                 $missing_fields = implode(', ', $missing_fields);\r
37                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));\r
38         }\r
39 \r
40         if (!$msg->containsErrors()) {\r
41                 $_GET['url'] = $addslashes($_GET['url']);\r
42                 \r
43                 $sql    = "REPLACE INTO ".TABLE_PREFIX."feeds VALUES(".$feed_id.", '".$_GET['url']."')";\r
44                 $result = mysql_query($sql, $db);\r
45 \r
46                 //update language\r
47                 if ($f = @fopen($title_file, 'w')) {\r
48                         fwrite($f, $_GET['title'], strlen($_GET['title']));\r
49                         fclose($f);\r
50                 }\r
51 \r
52                 //delete old cache file\r
53                 @unlink(AT_CONTENT_DIR.'/feeds/'.$feed_id.'_rss.cache');\r
54 \r
55                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');\r
56                 header('Location: index.php');\r
57                 exit;\r
58         } \r
59 \r
60 } else if (isset($_GET['cancel'])) {\r
61         $msg->addFeedback('CANCELLED');\r
62         header("Location:index.php");\r
63         exit;\r
64 }\r
65 \r
66 if ($feed_id != '') {\r
67 \r
68         $sql    = "SELECT * FROM ".TABLE_PREFIX."feeds WHERE feed_id=".$feed_id;\r
69         $result = mysql_query($sql, $db);\r
70         $row = mysql_fetch_assoc($result);\r
71         \r
72         if (file_exists($title_file)) {\r
73                 $_GET['title'] = file_get_contents($title_file);\r
74         }\r
75         $_GET['url'] = $row['url'];\r
76\r
77 \r
78 $onload = 'document.form.title.focus();';\r
79 \r
80 require (AT_INCLUDE_PATH.'header.inc.php');\r
81 $savant->assign('feed_id', $feed_id);\r
82 $savant->display('admin/system_preferences/edit_feed.tmpl.php');\r
83 require (AT_INCLUDE_PATH.'footer.inc.php'); ?>