826595591a668639db0dcbbff94e35b371f3a0d1
[atutor.git] / mods / basiclti / tool / admin_edit.php
1 <?php
2 define('AT_INCLUDE_PATH', '../../../include/');
3 require(AT_INCLUDE_PATH.'vitals.inc.php');
4 admin_authenticate(AT_ADMIN_PRIV_BASICLTI);
5
6 require_once('forms.php');
7 if($_POST['submit']){
8         // filter all POST data
9         $_POST['form_basiclti'] = $addslashes($_POST['form_basiclti']);
10         $_POST['title'] = $addslashes($_POST['title']);
11         $_POST['toolid'] = $addslashes($_POST['toolid']);
12         $_POST['description'] = $addslashes($_POST['description']);
13         $_POST['toolurl'] = $addslashes($_POST['toolurl']);
14         $_POST['resourcekey'] = $addslashes($_POST['resourcekey']);
15         $_POST['password'] = $addslashes($_POST['password']);
16         $_POST['preferheight'] = intval($_POST['preferheight']);
17         $_POST['allowpreferheight'] = intval($_POST['allowpreferheight']);
18         $_POST['launchinpopup'] = intval($_POST['launchinpopup']);
19         $_POST['debuglaunch'] = intval($_POST['debuglaunch']);
20         $_POST['sendname'] = intval($_POST['sendname']);
21         $_POST['sendemailaddr'] = intval($_POST['sendemailaddr']);
22         $_POST['acceptgrades'] = intval($_POST['acceptgrades']);
23         $_POST['allowroster'] = intval($_POST['allowroster']);
24         $_POST['allowsetting'] = intval($_POST['allowsetting']);
25         $_POST['allowcustomparameters'] = intval($_POST['allowcustomparameters']);
26         $_POST['customparameters'] = $addslashes($_POST['customparameters']);
27         $_POST['organizationid'] = $addslashes($_POST['organizationid']);
28         $_POST['organizationurl'] = $addslashes($_POST['organizationurl']);
29 //      $_POST['organizationdescr'] = $addslashes($_POST['organizationdescr']);
30         $_POST['submit'] = $addslashes($_POST['submit']);
31 }
32 $tool = intval($_REQUEST['id']);
33
34 if (isset($_POST['cancel'])) {
35         $msg->addFeedback('CANCELLED');
36         header('Location: '.AT_BASE_HREF.'mods/basiclti/index_admin.php');
37         exit;
38 } else if (isset($_POST['form_basiclti'], $tool)) {
39
40     if ( at_form_validate($blti_admin_form, $msg) ) {
41         global $addslashes;
42         $sql = "SELECT count(*) cnt FROM ".TABLE_PREFIX."basiclti_tools WHERE toolid = '".
43                 $addslashes($_POST['toolid'])."' AND id != $tool;";
44         $result = mysql_query($sql, $db) or die(mysql_error());
45         $row = mysql_fetch_assoc($result);
46
47         if ($row["cnt"] != 0) {
48            $msg->addFeedback('NEED_UNIQUE_TOOLID');
49         } else {
50             $sql = at_form_update($_POST, $blti_admin_form);
51             $sql = 'UPDATE '.TABLE_PREFIX."basiclti_tools SET ".$sql." WHERE id = $tool;";
52             $result = mysql_query($sql, $db) or die(mysql_error());
53             write_to_log(AT_ADMIN_LOG_INSERT, 'basiclti_create', mysql_affected_rows($db), $sql);
54             $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
55             header('Location: '.AT_BASE_HREF.'mods/basiclti/index_admin.php');
56             exit;
57         }
58     }
59 }
60
61 $sql = "SELECT * FROM ".TABLE_PREFIX."basiclti_tools WHERE id = ".$tool.";";
62 $result = mysql_query($sql, $db) or die(mysql_error());
63 $toolrow = mysql_fetch_assoc($result);
64 if ( $toolrow['id'] != $tool ) {
65     $msg->addFeedback('COULD_NOT_LOAD_TOOL');
66     header('Location: '.AT_BASE_HREF.'mods/basiclti/index_admin.php');
67     exit;
68 }
69
70 include(AT_INCLUDE_PATH.'header.inc.php');
71
72 $msg->printAll();
73
74 ?>
75 <form method="post" action="<?php echo $_SERVER['PHP_SELF'];  ?>" name="basiclti_form" enctype="multipart/form-data">
76   <input type="hidden" name="form_basiclti" value="true" />
77   <input type="hidden" name="id" value="<?php echo $tool; ?>" />
78   <div class="input-form">
79     <fieldset class="group_form"><legend class="group_form"><?php echo _AT('properties'); ?></legend>
80 <?php at_form_generate($toolrow, $blti_admin_form); ?>
81         <div class="buttons">
82                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
83                 <input type="submit" name="cancel" value="<?php echo _AT('cancel');?>" />
84         </div>
85     </fieldset>
86   </div>
87 </form>
88
89 <?php
90 require(AT_INCLUDE_PATH.'footer.inc.php');