SVN tag for release should only contain scripts in "docs" folder without "mods",...
[atutor.git] / docs / 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 \r
77 require (AT_INCLUDE_PATH.'header.inc.php');\r
78 \r
79 if (!isset($_POST['confirm'])) {\r
80 ?>\r
81         <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">\r
82                 <input type="hidden" name="confirm" value="1" />\r
83 \r
84                 <div class="input-form" style="width: 95%x">\r
85                         <div class="row">\r
86                                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php echo _AT('title'); ?></label><br />\r
87                                 <input id="title" name="title" type="text" size="60" maxlength="255" value="<?php echo $stripslashes(htmlspecialchars($_POST['title'])); ?>" /><br />\r
88                         </div>\r
89 \r
90                         <div class="row">\r
91                                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="url"><?php echo _AT('url'); ?></label><br />\r
92                                 <input id="url" name="url" type="text" size="60" maxlength="255" value="<?php echo $stripslashes(htmlspecialchars($_POST['url'])); ?>" /><br />\r
93                         </div>\r
94 \r
95                         <div class="row buttons">\r
96                                 <input type="submit" name="submit" value=" <?php echo _AT('save'); ?> " accesskey="s" />\r
97                                 <input type="submit" name="cancel" value=" <?php echo _AT('cancel'); ?> " />\r
98                         </div>\r
99                 </div>\r
100         </form>\r
101 <?php \r
102 } else { ?>\r
103 \r
104         <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">\r
105         <input type="hidden" name="new" value="<?php echo $_POST['new']; ?>" />\r
106 \r
107         <div class="input-form">\r
108                 <div class="row">\r
109                         <h3><?php if (file_exists($title_file)) { \r
110                                         readfile($title_file); \r
111                                 } else {\r
112                                         echo $_POST['title'];\r
113                                 }?>\r
114                         </h3>\r
115                 </div>\r
116 \r
117                 <div class="row">\r
118                         <?php echo $output; ?>\r
119                 </div>\r
120         </div>\r
121         </form>\r
122 \r
123         <?php\r
124                 $hidden_vars['new'] = '1';\r
125                 $hidden_vars['title'] = $_POST['title'];\r
126                 $hidden_vars['url'] = $_POST['url'];\r
127 \r
128                 $msg->addConfirm('ADD_FEED', $hidden_vars);\r
129                 $msg->printConfirm();\r
130         ?>\r
131 \r
132 <?php \r
133 }\r
134 ?>\r
135 \r
136 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>