move code up one directory
[atutor.git] / mods / _standard / links / add.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 if (!$_SESSION['enroll']) {\r
19         $msg->addInfo('NOT_ENROLLED');\r
20         require(AT_INCLUDE_PATH.'header.inc.php');\r
21         require(AT_INCLUDE_PATH.'footer.inc.php');\r
22         exit;\r
23 }\r
24 \r
25 require (AT_INCLUDE_PATH.'../mods/_standard/links/lib/links.inc.php');\r
26 \r
27 if (!manage_links()) {\r
28         $_pages['mods/_standard/links/index.php']['children']  = array('mods/_standard/links/add.php');\r
29 }\r
30 \r
31 if (!isset($_POST['url'])) {\r
32         $_POST['url'] = "http://";\r
33 }\r
34 \r
35 if (isset($_POST['cancel'])) {\r
36         $msg->addFeedback('CANCELLED');\r
37         header('Location: '.AT_BASE_HREF.'mods/_standard/links/index.php');\r
38         exit;\r
39 } else if (isset($_POST['add_link']) && isset($_POST['submit'])) {\r
40         $missing_fields = array();\r
41         if ($_POST['cat'] == 0 || $_POST['cat'] == '') {\r
42                 $missing_fields[] = _AT('category');\r
43         }\r
44         if (trim($_POST['title']) == '') {\r
45                 $missing_fields[] = _AT('title');\r
46         }\r
47         if (trim($_POST['url']) == '' || $_POST['url'] == 'http://') {\r
48                 $missing_fields[] = _AT('url');\r
49         }\r
50         if (trim($_POST['description']) == '') {\r
51                 $missing_fields[] = _AT('description');\r
52         }\r
53 \r
54         if ($missing_fields) {\r
55                 $missing_fields = implode(', ', $missing_fields);\r
56                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));\r
57         }\r
58 \r
59 \r
60         if (!$msg->containsErrors() && isset($_POST['submit'])) {\r
61 \r
62                 $_POST['cat'] = intval($_POST['cat']);\r
63                 $_POST['title']  = $addslashes($_POST['title']);\r
64                 $_POST['url'] == $addslashes($_POST['url']);\r
65                 $_POST['description']  = $addslashes($_POST['description']);\r
66 \r
67                 $name = get_display_name($_SESSION['member_id']);\r
68                 $email = '';\r
69 \r
70                 $approved = 0; //not approved for student submissions\r
71 \r
72                 $sql    = "INSERT INTO ".TABLE_PREFIX."links VALUES (NULL, $_POST[cat], '$_POST[url]', '$_POST[title]', '$_POST[description]', $approved, '$name', '$email', NOW(), 0)";\r
73                 mysql_query($sql, $db);\r
74         \r
75                 $msg->addFeedback('LINK_ADDED');\r
76 \r
77                 header('Location: '.AT_BASE_HREF.'mods/_standard/links/index.php');\r
78                 exit;\r
79         } else {\r
80                 $_POST['title']  = stripslashes($_POST['title']);\r
81                 $_POST['url'] == stripslashes($_POST['url']);\r
82                 $_POST['description']  = stripslashes($_POST['description']);\r
83         }\r
84 }\r
85 $onload = 'document.form.title.focus();';\r
86 \r
87 require(AT_INCLUDE_PATH.'header.inc.php');\r
88 \r
89 $categories = get_link_categories();\r
90 \r
91 if (empty($categories)) {\r
92         $msg->addInfo('NO_LINK_CATEGORIES');\r
93         $msg->printInfos();\r
94 \r
95 } else {\r
96 ?>\r
97 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">\r
98 <input type="hidden" name="add_link" value="true" />\r
99 \r
100 <div class="input-form">\r
101         <div class="row">\r
102                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php echo _AT('title'); ?></label><br />\r
103                 <input type="text" name="title" size="40" id="title" value="<?php echo AT_print($_POST['title'], 'input.text'); ?>"/>\r
104         </div>\r
105 \r
106         <div class="row">\r
107                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="cat"><?php echo _AT('category'); ?></label><br />\r
108                 <select name="cat" id="cat"><?php\r
109                         if ($pcat_id) {\r
110                                 $current_cat_id = $pcat_id;\r
111                                 $exclude = false; /* don't exclude the children */\r
112                         } else {\r
113                                 $current_cat_id = $cat_id;\r
114                                 $exclude = true; /* exclude the children */\r
115                         }\r
116                         select_link_categories($categories, 0, $_POST['cat'], FALSE);\r
117                         ?>\r
118                 </select>\r
119         </div>\r
120         \r
121         <div class="row">\r
122                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="url"><?php echo _AT('url'); ?></label><br />\r
123                 <input type="text" name="url" size="40" id="url" value="<?php echo AT_print($_POST['url'], 'input.text'); ?>" />\r
124         </div>\r
125 \r
126         <div class="row">\r
127                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="description"><?php echo _AT('description'); ?></label><br />\r
128                 <textarea name="description" cols="55" rows="2" id="description" ><?php echo AT_print($_POST['description'], 'input.text'); ?></textarea>\r
129         </div>\r
130         \r
131         <div class="row buttons">\r
132                 <input type="submit" name="submit" value="<?php echo _AT('submit'); ?>" accesskey="s" />\r
133                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?> " />\r
134         </div>\r
135 </div>\r
136 </form>\r
137 \r
138 <?php \r
139 }       \r
140 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>