remove old readme
[atutor.git] / mods / _standard / links / tools / edit.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 require (AT_INCLUDE_PATH.'../mods/_standard/links/lib/links.inc.php');\r
18 \r
19 if (!manage_links()) {\r
20         $msg->addError('ACCESS_DENIED');\r
21         header('Location: '.AT_BASE_HREF.'mods/_standard/links/index.php');\r
22         exit;\r
23 }\r
24 \r
25 $lid = explode('-', $_REQUEST['lid']);\r
26 $link_id = intval($lid[0]);\r
27 \r
28 if (isset($_POST['cancel'])) {\r
29         $msg->addFeedback('CANCELLED');\r
30         header('Location: '.AT_BASE_HREF.'mods/_standard/links/tools/index.php');\r
31         exit;\r
32 } else if (isset($_POST['edit_link']) && isset($_POST['submit'])) {\r
33 \r
34         $missing_fields = array();\r
35         if ($_POST['cat'] == 0 || $_POST['cat'] == '') {\r
36                 $missing_fields[] = _AT('category');\r
37         }\r
38         if (trim($_POST['title']) == '') {\r
39                 $missing_fields[] = _AT('title');\r
40         }\r
41         if (trim($_POST['url']) == '' || $_POST['url'] == 'http://') {\r
42                 $missing_fields[] = _AT('url');\r
43         }\r
44         if (trim($_POST['description']) == '') {\r
45                 $missing_fields[] = _AT('description');\r
46         }\r
47 \r
48         if ($missing_fields) {\r
49                 $missing_fields = implode(', ', $missing_fields);\r
50                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));\r
51         }\r
52 \r
53         if (!$msg->containsErrors() && isset($_POST['submit'])) {\r
54 \r
55                 $_POST['cat'] = intval($_POST['cat']);\r
56                 $_POST['title']  = $addslashes($_POST['title']);\r
57                 $_POST['url'] == $addslashes($_POST['url']);\r
58                 $_POST['description']  = $addslashes($_POST['description']);\r
59                 //Check length of the post, if it's exceeded 64 as defined in the db. \r
60                 $_POST['title'] = validate_length($_POST['title'], 64);\r
61                 $_POST['description'] = validate_length($_POST['description'], 250);\r
62 \r
63 //              $name = get_display_name($_SESSION['member_id']);\r
64                 $email = '';\r
65 \r
66                 //check if new cat is auth? -- shouldn't be a prob. since cat dropdown is already filtered\r
67 \r
68                 $sql    = "UPDATE ".TABLE_PREFIX."links SET cat_id=$_POST[cat], Url='$_POST[url]', LinkName='$_POST[title]', Description='$_POST[description]', Approved=$_POST[approved] WHERE link_id=".$link_id;\r
69                 mysql_query($sql, $db);\r
70         \r
71                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');\r
72 \r
73                 header('Location: '.AT_BASE_HREF.'mods/_standard/links/tools/index.php');\r
74                 exit;\r
75         } else {\r
76                 $_POST['title']  = $stripslashes($_POST['title']);\r
77                 $_POST['url']    = $stripslashes($_POST['url']);\r
78                 $_POST['description'] = $stripslashes($_POST['description']);\r
79         }\r
80 } else {\r
81         $sql = "SELECT * FROM ".TABLE_PREFIX."links WHERE link_id=".$link_id;\r
82         $result = mysql_query($sql, $db);\r
83         if ($row = mysql_fetch_assoc($result)) {\r
84 \r
85                 //auth based on the link's cat\r
86                 $cat_row = get_cat_info($row['cat_id']);\r
87 \r
88                 if (!links_authenticate($cat_row['owner_type'], $cat_row['owner_id'])) {\r
89                         $msg->addError('ACCESS_DENIED');\r
90                         header('Location: '.AT_BASE_HREF.'mods/_standard/links/tools/index.php');\r
91                         exit;\r
92                 }\r
93 \r
94                 $_POST['title']                 = $row['LinkName'];\r
95                 $_POST['cat']                   = $row['cat_id'];\r
96                 $_POST['url']                   = $row['Url'];\r
97                 $_POST['description']   = $row['Description'];\r
98                 $_POST['approved']              = $row['Approved'];\r
99         }\r
100 }\r
101 \r
102 $onload = 'document.form.title.focus();';\r
103 require(AT_INCLUDE_PATH.'header.inc.php');\r
104 \r
105 $categories = get_link_categories(true);\r
106 \r
107 $msg->printErrors();\r
108 \r
109 ?>\r
110 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">\r
111 <input type="hidden" name="edit_link" value="true" />\r
112 <input type="hidden" name="lid" value="<?php echo $_REQUEST['lid']; ?>" />\r
113 \r
114 <div class="input-form">\r
115         <div class="row">\r
116                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php echo _AT('title'); ?></label><br />\r
117                 <input type="text" name="title" size="40" id="title" value="<?php echo $_POST['title']; ?>"/>\r
118         </div>\r
119 \r
120         <div class="row">\r
121                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="cat"><?php echo _AT('category'); ?></label><br />\r
122                 <select name="cat" id="cat">\r
123                         <?php select_link_categories($categories, 0, $_POST['cat'], FALSE);     ?>\r
124                 </select>\r
125         </div>\r
126         \r
127         <div class="row">\r
128                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="url"><?php echo _AT('url'); ?></label><br />\r
129                 <input type="text" name="url" size="40" id="url" value="<?php echo $_POST['url']; ?>" />\r
130         </div>\r
131 \r
132         <div class="row">\r
133                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="description"><?php echo _AT('description'); ?></label><br />\r
134                 <textarea name="description" cols="55" rows="5" id="description" ><?php echo $_POST['description']; ?></textarea>\r
135         </div>\r
136 \r
137         <div class="row">\r
138                 <?php echo _AT('approve'); ?><br />\r
139                 <?php\r
140                         if ($_POST['approved']) {\r
141                                 $y = 'checked="checked"';\r
142                                 $n = '';\r
143                         } else {\r
144                                 $n = 'checked="checked"';\r
145                                 $y = '';\r
146                         }\r
147                 ?>\r
148                 <input type="radio" id="yes" name="approved" value="1" <?php echo $y; ?> /><label for="yes"><?php echo _AT('yes'); ?></label>  <input type="radio" id="no" name="approved" value="0" <?php echo $n; ?> /><label for="no"><?php echo _AT('no'); ?></label>\r
149         </div>\r
150         \r
151         <div class="row buttons">\r
152                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />\r
153                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?> " />\r
154         </div>\r
155 </div>\r
156 </form>\r
157 \r
158 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>