Odyssey
uplremove.prg
1 <?php
2 $monLibrary= dirname(__FILE__) . "/../library";
3 require_once("$monLibrary/cu_top.i");
4 require_once("$monLibrary/ck_hticket.i");
5 
6  if (!CheckPerm($link, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR'])) {
7  // ** Permissions failed
8  // ** redirect to new page
9  header("Location: /hcuadm/hcu_noperm.prg");
10  exit;
11  }
12 
13 $dms_ok=array('w'=>'digits','cu'=>'string','remove_daz'=>'string');
14 
15 dms_import($dms_ok);
16 
17  if (isset($w) == false || $w > 2) $w = "1";
18 
19  $dbh = $link;
20 
21  $uplfilename = RetrieveFileName($cu);
22  switch ($w):
23 
24  case "1":
25  cu_header("Delete Upload Files");
26 
27 ?>
28  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
29  <input type="hidden" value="<?php echo $cu; ?>" name="cu">
30  <input type="hidden" value="2" name="w">
31  <table border=0 align=center cellpadding=3 cellspacing=0 width=500 class="dmsbg"><tr><td>
32  <table border=0 cellpadding=1 cellspacing=0 width="100%" bgcolor=white>
33  <tr>
34  <td class='bar' align=center>
35  Delete Upload File
36  </td>
37  </tr>
38  <tr>
39  <td align=center class='dtl'>
40  <font size="4" color="red">
41  WARNING!<br>
42  This will delete the <?php echo $uplfilename; ?>.dat file. <br>Be sure this is what you want to do
43  </font>
44  </td>
45  </tr>
46  <tr>
47  <td class='dtl'>
48  Delete the <?php echo $uplfilename; ?>.dat file for <?php echo strtoupper($cu); ?>?
49  </td>
50  </tr>
51  <tr>
52  <td class='dtl'>
53  <input type="submit" value="Yes" name="remove_daz">
54  <!-- <input type="submit" value="No" name="keep_daz"> -->
55  </td>
56  </tr>
57  </table>
58  </td></tr></table>
59 <?php
60  break;
61  case "2":
62  // This part of the form will be used for saving the flag
63  $err = false;
64  if ((isset($remove_daz)) && isset($cu)) {
65  // Remove the FILE HERE
66  // $filename = "/home/$cu/tmp/$cu.dat"; // **OLD Replaced to to use uplfilename
67  $filename = "/home/$cu/tmp/$uplfilename.dat";
68  if (is_file($filename)) {
69  // File FOUND now -- figure if I should delete or not
70  if (is_writeable($filename)) {
71  // -- Should be able to delete the file
72  if (unlink($filename) == true) {
73  // The file should now be deleted
74  // Try to delete the daz file if it is there, just to make sure
75  $filenamez = "/home/$cu/tmp/$uplfilename.daz";
76  if (is_file($filenamez)) {
77  unlink($filenamez);
78  }
79  $err = false;
80  } else {
81  $add_msg = "<br><br>I tried to delete the file, but could not. Please contact a system administrator to delete the file.";
82  }
83  } else {
84  // -- File is NOT deletable
85  $add_msg = "<br><br>The file was found, but it can not be deleted. Please contact a system administrator to delete.";
86  $err = true;
87  }
88  }
89  } else {
90  $err = true;
91  }
92 
93  if ($err == true) {
94  cu_header("Error Deleting File");
95  print ("<form>");
96  cu_message("Unexpected errors!$add_msg");
97  } else {
98  cu_header("File Deleted");
99  $msg = "The $cu.daz file was deleted.<br>The Credit Union should be able to upload the file again.";
100  print <<< print_html
101  <table border=0 align=center cellpadding=3 cellspacing=0 width=500 class="dmsbg"><tr><td>
102  <table border=0 cellpadding=1 cellspacing=0 width="100%" bgcolor=white>
103  <tr>
104  <td class='bar' align=center>
105  File Deleted
106  </td>
107  </tr>
108  <tr>
109  <td align=center class='dtl'>
110  <font size="3" color="red">
111  $msg
112  </font>
113  </td>
114  </tr>
115  </table>
116  </td></tr></table>
117 print_html;
118  }
119  break;
120  endswitch;
121 ?>
122 
123  </form>
124  </body>
125  </html>
126 <?php
127  function RetrieveFileName($cuname) {
128 
129  /*
130  1st -- I will look for the file using all the credit union digits
131  -- if this is FOUND then great
132  -- if this is FALSE, then we trim the cu name to 6 digits and look for
133  -- it again. If found then great, if not then return the cuname anyway???
134  */
135 
136  $lookforname = $cuname;
137 
138  $tmpfilename = "/home/$cuname/tmp/$lookforname.dat";
139  if (is_file($tmpfilename)) {
140  // ** FOUND the name using the regular cuname
141  return $lookforname;
142  } else {
143  // ** NOT FOUND -- take only the first 6 digits and look again
144  $lookforname = substr($cuname, 0, 6);
145  $tmpfilename = "/home/$cuname/tmp/$lookforname.dat";
146  if (is_file($tmpfilename)) {
147  return $lookforname;
148  } else {
149  return $cuname;
150  }
151  }
152 
153  // ** Trully should not get here
154  return "";
155  }
156 ?>