remove old readme
[atutor.git] / mods / _standard / rss_feeds / add_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 if (isset($_POST['cancel'])) {\r
21         $msg->addFeedback('CANCELLED');\r
22         header("Location: index_admin.php");\r
23         exit;\r
24 } else if (isset($_POST['submit'])) {\r
25         $missing_fields = array();\r
26 \r
27         if (trim($_POST['title']) == '') {\r
28                 $missing_fields[] = _AT('title');\r
29         }\r
30         if (trim($_POST['url']) == '') {\r
31                 $missing_fields[] = _AT('url');\r
32         }\r
33         if ($missing_fields) {\r
34                 $missing_fields = implode(', ', $missing_fields);\r
35                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));\r
36         }\r
37 \r
38         if (!$msg->containsErrors()) {\r
39                 $output = make_cache_file(0);\r
40                 if (!isset($output) || empty($output)) {\r
41                         $msg->addError('FEED_NO_CONTENT');\r
42                 }\r
43         }\r
44 \r
45         if ($msg->containsErrors()) {\r
46                 unset($_POST['confirm']);\r
47         }\r
48 \r
49 } else if (isset($_POST['submit_no'])) {\r
50         $msg->addFeedback('CANCELLED');\r
51 \r
52 } else if (isset($_POST['submit_yes'])) {\r
53         $_POST['url'] = $addslashes($_POST['url']);\r
54 \r
55         $sql    = "INSERT INTO ".TABLE_PREFIX."feeds VALUES (NULL, '".$_POST['url']."')";\r
56         $result = mysql_query($sql, $db);\r
57 \r
58         $feed_id = mysql_insert_id($db);\r
59         \r
60         //copy load file\r
61         copy('load_file.php', AT_CONTENT_DIR.'feeds/'.$feed_id.'_rss.inc.php');\r
62 \r
63         //add language\r
64         $title_file = AT_CONTENT_DIR.'feeds/'.$feed_id.'_rss_title.cache';\r
65         if ($f = @fopen($title_file, 'w')) {\r
66                 fwrite ($f, $_POST['title'], strlen($_POST['title']));\r
67                 fclose($f);\r
68         }\r
69 \r
70         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');\r
71         header('Location: index.php');\r
72         exit;\r
73\r
74 \r
75 $onload = 'document.form.title.focus();';\r
76 $hidden_vars['new'] = '1';\r
77 $hidden_vars['title'] = $_POST['title'];\r
78 $hidden_vars['url'] = $_POST['url'];\r
79 \r
80 $msg->addConfirm('ADD_FEED', $hidden_vars);\r
81 require (AT_INCLUDE_PATH.'header.inc.php');\r
82 \r
83 $savant->assign('msg', $msg);\r
84 $savant->assign('output', $output);\r
85 $savant->assign('title_file', $title_file);\r
86 $savant->display('admin/system_preferences/add_feed.tmpl.php');\r
87 require (AT_INCLUDE_PATH.'footer.inc.php'); ?>