Odyssey
DocMaint.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('action'=>'string','MAX_FILE_SIZE'=>'string','csub'=>'string',
14 'upload_file'=>'string','Upload'=>'string','delete'=>'array',
15 'DFiles'=>'string','mdir'=>'string','newfolder'=>'string',
16 'ndir'=>'string','cpath'=>'string','view'=>'string','efile'=>'string','cdir'=>'string',
17 'script_doc'=>'string', 'act'=>'string');
18 dms_import($dms_ok);
19 
20  $msg = "";
21 
22 $top_upload = false; // Allow file upload for the top directory
23 $top_dir="/home/httpd/homecu/monitor/hcudocs"; // Top Most Directory
24 $HCUDocs_MaxPreviousVersion = 5;
25 
26 // Create two arrays - for files and directories
27 // these are the viewable files in the top directory
28 $allowed_dir = array();
29 $allowed_files = array();
30 $allowed_subs=array();
31 
32 // Settings for Subdirectory Control
33 $allow_subdir = true; // This will control if the user may make subdirectories under the main directories (ie. board employees)
34 $max_subdir = 50; // This is the maximum number of directories allowed in any one directory
35 $allow_multi_subdir = true; // This is intended to control creation of subdirectories 2 directories and further below hcudocs
36 
37 // Setup the directories allowed
38 // Add any directories here to include in the html list if they exist
39 $allowed_dir[] = "HomeCU";
40 $allowed_subs[]="";
41 $allowed_dir[] = "Core_Vendors";
42 $allowed_subs[]="select trim(vendor) from cuvendors order by vendor;";
43 $allowed_dir[] = "Image_Vendors";
44 $allowed_subs[]="select trim(img) from cuimagevendors order by img;";
45 $allowed_dir[] = "SSO_Partners";
46 $allowed_subs[]="select trim(ssovendor) from cussovendors order by ssovendor;";
47 
48 if ((isset($ndir) == true && strlen($ndir) > 0) ) {
49  if ($ndir == "..") {
50  // Move up the directory -- Need to remove the last directory from the csub piece, this will also be the ndir variable
51  if (strpos(strrev($csub), "/") !== false) {
52  $cdir = substr($csub, 0, strlen($csub) - strpos(strrev($csub), "/") - 1);
53  $cpath = $top_dir . ($cdir == '' ? "" : "/$cdir");
54  $csub = substr($cpath, strpos($cpath,$top_dir) + 1 + strlen($top_dir));
55  } else {
56  $cdir = '';
57  $csub = '';
58  $cpath = $top_dir;
59  }
60  } else {
61  $cdir = $ndir;
62  $cpath = $top_dir . ($csub == '' ? "" : "/$csub") . "/$ndir";
63  $csub = substr($cpath, strpos($cpath,$top_dir) + 1 + strlen($top_dir));
64  }
65 } elseif (isset($csub) == true) {
66  $cpath = $top_dir . ($csub == '' ? "" : "/$csub");
67  if (strpos($csub,"/")) {
68  $cdir = substr(strrchr($csub, "/"), 1);
69  } else {
70  $cdir=$csub;
71  }
72  #$msg="csub $csub : cpath $cpath : cdir $cdir";
73 } else {
74 // Place code here so if any of these variable are NOT set, then we start over on the rotation
75  $cdir = "";
76  $csub = "";
77  $cpath = $top_dir;
78 }
79 if (!is_dir($cpath)) {
80  $msg="Requested subdirectory $ndir not found. Starting at the top!";
81  $cdir = "";
82  $csub = "";
83  $cpath = $top_dir;
84 }
85 
86 
87 // Create the direcotry name that is on top of the top_dir
88 // So if the current directory is /home/xyz/public_html/employees/sample
89 // This should return employees/sample
90 if (strpos($cpath, $top_dir) !== false) {
91  $dir_pos = strpos($cpath, $top_dir);
92  $cspath = substr($cpath, $dir_pos + 1 + strlen($top_dir)); // This should be the just the path information past the top_dir
93 } else {
94  $cspath = '';
95 }
96 
97 //echo "cspath-$cspath<br>";
98 
99 
100 $self=$_SERVER['PHP_SELF'];
101 
102 $action = (empty($action) ? "none" : $action);
103 $action = strtolower($action);
104 
105 switch ($action) {
106  case "view":
107  view_form();
108  break;
109  case "upload":
110  // Post all information on the form, then reload the print_status screen
111  post_form();
112  print_status();
113  break;
114  case "createsub":
115  $msg = "";
116  create_subdir();
117  print_status();
118  break;
119  case "create":
120  $msg = "";
121  create_dir();
122  print_status();
123  break;
124  case "edit":
125  edit_form();
126  break;
127  case "restore":
128  restore_file();
129  print_status();
130  break;
131  case "saveedit":
132  save_form();
133  print_status();
134  break;
135  default:
136  print_status();
137  break;
138  }
139 
140 
141 //echo "<table><tr><td><hr><br>";
142 //while (list ($key, $val) = each ($GLOBALS)) { echo ("Element $key equals $val<br>\n"); }
143 //echo "</td></tr></table>";
144 //exit;
145 
146 /* ------------------------------------- */
147  function create_dir() {
148  global $msg, $mdir, $top_dir, $cpath, $csub, $cdir, $allowed_dir;
149 
150  $dir_to_create = "";
151  // This will attempt to create the directory in the credit unions public_html directory
152  $path_to_dir = "";
153 
154  $dir_to_create = trim($mdir);
155  if (strlen($dir_to_create) == 0) {
156  $msg = "Problem creating the directory. Please select again.";
157  } else {
158  if (in_array($mdir, $allowed_dir)) {
159  $path_to_dir = $top_dir . "/" . $dir_to_create;
160  } else {
161  $cdir = basename(rtrim($cpath, '/'));
162  $path_to_dir = $cpath . "/" . $dir_to_create;
163  }
164  // Now look to see if the directory is created
165  if (is_dir($path_to_dir)) {
166  $msg = "The directory already exists. It was not created.";
167  } else {
168  // here is where I try to create the directory
169  if (@mkdir($path_to_dir, 0755) === false) {
170  // Problem creating the directory, it failed
171  $msg = "Unknown error creating the directory ($path_to_dir). ";
172  } else {
173  // Operation a success -- tell the user
174  $msg = "SUCCESS -- a new folder named $dir_to_create was created.";
175  }
176  }
177  }
178  }
179 
180 /* ------------------------------------- */
181  function create_subdir() {
182  global $msg, $allowed_dir, $top_dir, $allow_subdir, $allow_multi_subdir, $max_subdir, $csub, $newfolder, $cdir;
183 
184  // Values from url --
185  // csub -- Current subdirectory the user was in, before trying to create a new folder
186  // newfolder -- the name of the new folder the credit union wants to make
187 
188  // First start with the most basic of tests
189  // 1. Are we allowing creation of subdirectories
190  $cdir = basename(rtrim(($top_dir . ($csub == '' ? "" : "/$csub")),'/'));
191  if ($allow_subdir == true) {
192  $dir_to_create = "";
193  // This will attempt to create the directory in the credit unions public_html directory
194  $mdir = intval($mdir);
195  $path_to_dir = "";
196 
197  // need to make sure csub and newfolder do not contain any weird characters
198  $newfolder = preg_replace("/\W/", "", $newfolder);
199 
200  $dir_to_create = trim($csub) . "/" . $newfolder;
201  if (strlen($dir_to_create) == 0) {
202  $msg = "Problem creating the directory. Please select again.";
203  } else {
204  // Okay so we are here --
205  // Now need to be sure they are not creating a multi-subdirectory
206  if ($allow_multi_subdir == true || ((array_search($csub, $allowed_dir) !== false))) {
207  // We are getting closer, but NOW we must be sure they have not
208  // exceeded the maximum number of subdirectories allowed
209 
210  $dirpath = $top_dir . "/" . $csub;
211  $dirlist = array();
212 
213  if ($fhandle = @opendir($dirpath)) {
214  while (false !== ($file = readdir($fhandle))) {
215  if (($file != ".") && ($file != "..") && (substr($file, 0, 1) != ".")) {
216  // Don't inlcude the current directory information
217  // Now check to see if this is a directory or file
218  if (is_dir($dirpath . "/" . $file)) {
219  // Only add directory names
220  $dirlist[count($dirlist)] = $file;
221  }
222  }
223  }
224  }
225 
226  $dirlist_count = count($dirlist);
227 
228  if ($dirlist_count < $max_subdir) {
229  $path_to_dir = $top_dir . "/" . $dir_to_create;
230  // Now look to see if the directory is created
231  if (is_dir($path_to_dir)) {
232  $msg = "The directory already exists. It can not be created.";
233  } else {
234  // here is where I try to create the directory
235  if (@mkdir($path_to_dir, 0755) === false) {
236  // Problem creating the directory, it failed
237  $msg = "Unknown error creating the directory. <br>
238  You may need to contact HomeCU for additional help .";
239  } else {
240  // Operation a success -- tell the user
241  $msg = "SUCCESS -- a new folder named $dir_to_create was created.";
242  }
243  }
244  } else {
245  // There are too many sub directories already, don't allow any more
246  $msg = "Maximum number of folders has been reached. You will need to remove a folder before adding additional.";
247  }
248  } else {
249  // We are NOT allowed subdirectories under subdirectories
250  $msg = "Unable to create the new folder. Custom folders are only allowed in the top most folder.";
251  }
252  }
253  } else {
254  // We are not allowing creation of subdirectories
255  // Possibly report that here
256  $msg = "Creating subdirectories is NOT allowed.";
257  }
258  }
259 /* ------------------------------------- */
260  function print_help($all=false) {
261  // This will print the show_help function for javascript
262  // if all == false, it will only print the function
263  // if all == true, it will also print the javascript tags
264  if ($all == true) {
265  print ("<script language=\"javascript\">\n
266  <!--");
267  }
268  // Here print the show_help function
269  print ("
270  function show_help(marker) {
271  var helpwin = null;
272  var wind_options = \"\";
273  wind_options = \"toolbar=1,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=500,height=340\";
274  helpwin=window.open(\"DocHelp.html#\" + marker,\"_Help\", wind_options);
275  helpwin.focus();
276  }
277  ");
278 
279  if ($all == true) {
280  print (" // -->\n
281  </script>");
282  }
283  }
284 
285 /* ------------------------------------- */
286  function img_help($mrk) {
287  return "<a href=\"javascript:show_help('$mrk');\"><img src=\"/monitor/images/q1.gif\" border=0 alt=\"View Help\" valign=\"top\"></a>";
288  }
289 
290 /* ------------------------------------- */
291  function print_status() {
292  global $msg, $dir, $self, $cdir, $cpath, $top_dir, $cspath, $csub, $allowed_dir, $allowed_subs, $allowed_files, $allow_subdir, $allow_multi_subdir, $max_subdir, $HCUDocs_MaxPreviousVersion, $view;
293 
294  header("Expires: Sat 20 May 1995 03:32:38 GMT");
295  header("Pragma: no-cache");
296  header("Cache-Control: no-cache, must-revalidate");
297 
298  global $link;
299 
300  // ** Setup ViewAll -- if view is ALL then true, else false
301  $viewAll = ($view == 'ALL' ? true : false);
302 
303  ?>
304 <?php
305  print "<html><head><title>HCU_Docs</title>
306  <LINK REL=stylesheet HREF='/monitor/css/monitor.css' TYPE='text/css'>
307  </head>
308  <body>";
309 ?>
310 <script type="text/javascript" language="javascript">
311  <!--
312  <?php print_help(); ?>
313 
314  function check_delete() {
315  var idx = 0;
316  var pt_del = false;
317 
318  // Need to check to see if any options are marked as deleted, if so then we need to
319  // confirm before deleting
320  if (document.forms[0].elements['delete[]'][idx] == null) {
321  // The value is NOT an array -- so check for the existence of only one element
322  if (document.forms[0].elements['delete[]'] != null) {
323  if (document.forms[0].elements['delete[]'].checked == true) {
324  pt_del = true;
325  }
326  }
327  } else {
328  while (document.forms[0].elements['delete[]'][idx]) {
329  if (document.forms[0].elements['delete[]'][idx].checked == true)
330  pt_del = true;
331  idx++;
332  }
333  }
334  if (pt_del == true) {
335  if (confirm('Are you sure you want to delete the selected files or folders?'))
336  return true;
337  else
338  return false;
339  } else {
340  return true;
341  }
342  }
343  function check_upload() {
344  var lastSlash // the position of the last slash in the path
345  var fileName // the name of the file
346  var directory // The directory
347  var fullPath = '';
348  var idx = 0;
349  var pt_ov = false;
350 
351  fullPath = document.forms[0].elements['upload_file'].value;
352  lastSlash = fullPath.lastIndexOf("\\")
353  fileName = fullPath.substring(lastSlash+1,fullPath.length)
354 
355  fileName = fileName.replace(/[ ;]{1}/g, "_");
356  // Now if filename is != ''
357  if (fileName == '') {
358  return false;
359  } else {
360  if (document.forms[0].elements['delete[]']) {
361  while (document.forms[0].elements['delete[]'][idx]) {
362  if (document.forms[0].elements['delete[]'][idx].value == fileName)
363  pt_ov = true;
364  idx++;
365  }
366  }
367 
368  if (pt_ov == true) {
369  if (confirm('You are about to overwrite the file "' + fileName + '". Is this what you want to do.')) {
370  //document.forms[0].elements['ndir'].value = "<?php echo $cdir; ?>";
371  return true;
372  } else
373  return false;
374  }
375  }
376  }
377  function confirm_dir(sdir) {
378  // This function will be used to confirm if they
379  // want to create the desired directory
380  var msg = "This will create the private directory '" + sdir + "'. Are you sure you want to continue?";
381  return confirm(msg);
382  }
383  function dir_create(sdir,csub) {
384 
385  // Send this form to itself
386  // Along with the action and mdir to create
387  var url = "";
388 
389  url = "<?php echo $self; ?>?action=create&csub=" + csub + "&mdir=" + sdir;
390  document.location = url;
391  }
392  function new_folder(cur_sub) {
393  var foldername = "";
394  var url = "";
395  foldername = window.prompt("Please enter a name for the new directory", "Folder1");
396 
397  if (foldername != null) {
398  // I want to strip out ALL non alpha-numeric characters that may have been entered
399  foldername = foldername.replace(/\W/g, "");
400  if (foldername.length > 30) {
401  window.alert ("The new folder name is NOT allowed to be more than 30 characters. Please enter a shorter name.");
402  } else {
403  url = "<?php echo $self;?>?action=createsub&csub=" + escape(cur_sub) + "&newfolder=" + foldername;
404  document.location = url;
405  }
406  }
407  }
408  // -->
409  </script>
410  <form method="post" action="<?php echo $self ?>" enctype="multipart/form-data" >
411  <input type="hidden" name="action" value="upload">
412  <input type="hidden" name="MAX_FILE_SIZE" value="15000000">
413  <input type="hidden" name="csub" value="<?php echo $cspath; ?>">
414  <input type="hidden" name="cdir" value="<?php echo $cdir; ?>">
415  <input type="hidden" name="cpath" value="<?php echo $cpath; ?>">
416  <br><div align=center><table width=95% border=0 cellspacing=0 cellpadding=4>
417  <tr><td colspan=4 class="bar" align=center>HomeCU Documents</td></tr>
418  <tr>
419  <td class="hdrl">&nbsp;</td>
420  <td class="hdrl"><a href="<?php echo $infourl; ?>/hcuadm/cuilist" target="_parent">Credit Union List</a></td>
421  <td colspan=2 class="hdrl"><?php echo ($cspath == "" ? "&nbsp;" : "Folder: &nbsp; $cspath"); ?></td>
422 </tr>
423  <?php if (!(($top_dir == $cpath) && ($top_upload == false))): ?>
424  <tr>
425  <td colspan="4" class="dtl" align="center">
426  Choose a File:
427  <input type="file" name="upload_file" size=30><?php echo img_help("choose"); ?>
428  &nbsp;&nbsp;&nbsp;<input type="submit" name="Upload" value="Upload File" onclick="return check_upload();">
429  <?php echo img_help("upload"); ?>
430  </td>
431  </tr>
432  <?php endif; ?>
433  <?php if ($msg != ""): ?>
434  <tr>
435  <td class="msg" colspan=1 align=right><img alt="black" src='/monitor/images/alert.black.gif'></td>
436  <td class="msg" colspan=3><?php echo $msg ?></td>
437  </tr>
438  <?php endif; ?>
439 
440  <?php
441  // Print out the files in this directory
442  // Also print the parent directory and any sub-directories
443 //echo "<br>READ DIRECTORY$cpath<br>";
444 
445  $dirlist = array();
446  $filelist = array();
447  if ($fhandle = @opendir($cpath)) {
448  while (false !== ($file = readdir($fhandle))) {
449  if (($file == "..") ) {
450  // This is the parent directory
451  // Make sure we will let them see this, it must not meet the top most directory
452  // Only let them go as High as top_dir
453  // Only include if the top_dir is located in the current path
454  //echo "cp-$cpath<br>td-$top_dir<br>cd-$cdir<br>strpos-" . strpos($cpath, $top_dir) . "<br>";
455  // also do NOT show the parent if the current directory is the same as the top directory
456  if ((strpos($cpath, $top_dir) !== false) && ($cpath != $top_dir)) {
457  //if ($cpath != ($top_dir . "/" . $cdir)) {
458  $dirlist[count($dirlist)] = $file;
459  // ONLY include IF the current directory and topmost path do NOT equal the current path
460  // This is an attempt to NOT allow directory viewing further up the tree then allowed
461  }
462  } elseif (($cpath == $top_dir)) {
463  // If the current path equals the top directory then ONLY show the
464  if (is_file($cpath . "/" . $file)) {
465  // Now check to see if the file is a viewable file
466  if (in_array($file, $allowed_files))
467  $filelist[count($filelist)] = $file;
468  } else {
469  // Check to see if the directory is viewable
470  if (in_array($file, $allowed_dir))
471  $dirlist[count($dirlist)] = $file;
472  }
473  // WHile I don't want to SHOW any hidden files, I do need to load them into the array here, I will be excluding them
474  // from showing in the next loop
475  // Don't show any hidden files, which start with a "." (unless viewAll is true)
476  // elseif (($file != ".") && ($file != "..") && (substr($file, 0, 1) != "."))
477  } elseif ((($file != ".") || $viewAll) && ($file != "..") ) {
478  // Don't inlcude the current directory information
479  // Now check to see if this is a directory or file
480  if (is_file($cpath . "/" . $file)) {
481  $filelist[count($filelist)] = $file;
482  } else {
483  if (substr($file, 0, 1) != ".") {
484  $dirlist[count($dirlist)] = $file;
485  }
486  }
487  }
488  }
489  } else {
490  //echo "Unable to Open";
491  }
492  ?>
493 
494  <?php
495  // If this is the top directory then print the "Active Directories" header
496  if ($cpath == $top_dir || in_array($cdir, $allowed_dir)) {
497  $help_act = img_help("active");
498  print <<< EOF
499  <tr>
500  <td class="hdr">&nbsp;</td>
501  <td class="hdr" colspan="3">
502  Active Directories $help_act
503  </td>
504  </tr>
505 EOF;
506  }
507  $dirlist_count = count($dirlist);
508  if ($dirlist_count > 0) {
509 // -- Sort the directories before printing them
510  array_multisort ($dirlist, SORT_ASC, SORT_STRING);
511  reset($dirlist);
512  $help_del = img_help("deletefolder");
513  foreach ($dirlist as $shortname) {
514  $ftime=date("m/d/y g:i:s A",filemtime("$cpath/$shortname"));
515  $fenc = urlencode($ftime);
516 
517  if ($shortname == "..") {
518  $dirname = "Parent Folder";
519  $dirgif = "pardir";
520  $helpdir = "&nbsp;" . img_help("parent");
521  $delurl = "";
522  } else {
523  $dirname = $shortname;
524  $dirgif = "folder";
525  $helpdir = "";
526  if ($cpath != $top_dir) {
527  $delurl = "<input type=\"checkbox\" name=\"delete[]\" value=\"$shortname\">Delete $help_del";
528  }
529  }
530  //$dirname = ($shortname == ".." ? "Parent Folder" : $shortname);
531 
532  $new_file_link = "<a href='$self?action=edit&act=NEW&csub=" . urlencode($csub) . "&cdir=" . urlencode($cdir) . "&efile=$viewpath'><img src='/monitor/images/new.gif' border='0' alt='New HTML File'></a>";
533  $all_file_link = "<a href='$self?csub=" . urlencode($csub) . "&cdir=" . urlencode($cdir) . ($view != "ALL" ? "&view=ALL" : "") . "'><img src='/monitor/images/quill.gif' border='0' alt='Show All Files'></a>";
534  print <<<EOF
535  <tr>
536  <td class="dtll">
537  <a href="$self?ndir=$shortname&csub=$cspath">
538  <img src='/monitor/images/{$dirgif}.gif' border='0' alt='Change Folders'></a>
539  </td>
540  <td class="dtll"><a href="$self?ndir=$shortname&csub=$cspath">$dirname</a>$helpdir</td>
541  <td class="dtll" nowrap>$ftime</td>
542  <td class="dtll" colspan="1">
543  $delurl
544  &nbsp;
545  </td>
546  </tr>
547 EOF;
548  // For the check w/ the max_subdir -- use <= because the parent folder will be included in the dirlist variable
549  if ($allow_subdir == true
550  && (($allow_multi_subdir == true || (array_search($cspath, $allowed_dir) !== false)) && $dirgif == "pardir")
551  && ($dirlist_count <= $max_subdir)) {
552  $helpdir = "&nbsp;" . img_help("newfolder");
553  // For the parent folder print the new folder icon beneath it
554  print <<<EOF
555  <tr>
556  <td class="dtll">
557  <a href="javascript:new_folder('$cspath')">
558  <img src='/monitor/images/folderin.gif' border='0' alt='New Folder'></a>
559  </td>
560  <td class="dtll"><a href="javascript:new_folder('$cspath')">New Folder</a>$helpdir</td>
561  <td class="dtll" nowrap>$ftime</td>
562  <td class="dtll" colspan="1">
563  &nbsp;
564  </td>
565  </tr>
566  <tr>
567  <td class="dtll" colspan="4"><hr></td>
568  </tr>
569  <tr>
570  <td class="dtll" colspan="4">
571  $new_file_link
572  $all_file_link
573  </td>
574  </tr>
575 EOF;
576  }
577  }
578  }
579  $filecount = 0;
580 
581  if (count($filelist) > 0) {
582  natsort($filelist);
583  reset($filelist);
584  foreach ($filelist as $shortname) {
585  $filecount++;
586  // ** HERE LIMIT the files being shown, do NOT show a file beginning with a "."
587 
588  if ((substr($shortname, 0, 1) != ".") || $viewAll) {
589 
590  // ** Build a possible list of versions for this file..
591  // * There is always a current
592  $ftime=date("m/d/y g:i:s A",filemtime("$cpath/$shortname"));
593  if ($viewAll) {
594  // ** VIEW ALL -- ONLY SHOW THE FILE version info
595  $file_version_list = "$ftime <input type='hidden' name='file_version_{$filecount}' value='$shortname'>";
596  } else {
597  $file_version_list="<option value='$shortname'>Current - $ftime</option>";
598  for ($idxFileVersion = 1; $idxFileVersion <= $HCUDocs_MaxPreviousVersion; $idxFileVersion++) {
599  $file_version_name = "$cpath/.{$shortname}.{$idxFileVersion}";
600 
601  if (file_exists($file_version_name)) {
602  $sel_file_val = ".$shortname.$idxFileVersion";
603  $ftime=date("m/d/y g:i:s A",filemtime($file_version_name));
604  $file_version_list .= "<option value='{$sel_file_val}'>{$ftime}</option>";
605  }
606  }
607  $file_version_list = "<select name=\"file_version_{$filecount}\" >$file_version_list </select>";
608  }
609 
610  // $ftime=date("m/d/y g:i:s A",filemtime("$cpath/$shortname"));
611  $fenc = urlencode($ftime);
612  $viewpath = urlencode("$shortname");
613 
614  $filepath = ($cspath == "" ? "/$viewpath" : "/$cspath/$viewpath");
615 
616  $help_del = img_help("delete");
617  $help_file = "&nbsp;" . img_help("filelist");
618 
619 
620  $show_edit_link = "";
621  if ((strtolower(substr($shortname, (strrpos($shortname, ".") === false ? strlen($shortname) : strrpos($shortname, ".")))) == ".html") && !$viewAll) {
622  $show_edit_link = "<a href='$self?action=edit&csub=" . urlencode($csub) . "&cdir=" . urlencode($cdir) . "&efile=$viewpath'><img src='/monitor/images/a.gif' border='0' alt='Edit File'></a>";
623  } elseif ($viewAll && substr($shortname, 0,1) == ".") {
624  $show_edit_link = "<a href='$self?action=restore&csub=" . urlencode($csub) . "&cdir=" . urlencode($cdir) . "&efile=$viewpath'><img src='/monitor/images/transfer.gif' border='0' alt='Restore File'></a>";
625  }
626  print <<<EOF
627  <script language="javascript">
628  <!--
629  function Build_File_Link( view_file_idx ) {
630 
631  // * Build the file from the option that is selected in the drop down.
632  // * they may really only VIEW the older files, EDIT is always the current
633  var file_root = "/monitor/hcudocs/$cspath";
634  var file_path = "";
635  var sel_object = document.getElementById("file_version_" + view_file_idx);
636  if (sel_object == null) {
637  sel_object = document.forms[0].elements['file_version_' + view_file_idx];
638  }
639 
640  if (sel_object == null) {
641  window.alert ('Unable to find the file you selected');
642 
643  } else {
644 
645  if (sel_object.type == "hidden") {
646  var sel_filename = sel_object.value;
647  var file_url = "";
648 
649  file_url = "$infourl" + file_root + "/" + sel_filename;
650  } else {
651  var sel_idx = sel_object.selectedIndex;
652  var sel_filename = sel_object.options[sel_idx].value;
653  var file_url = "";
654 
655  file_url = "$infourl" + file_root + "/" + sel_filename;
656 
657  }
658  // window.alert(file_url);
659  var newwin = null
660  newwin = window.open(file_url);
661  }
662 
663  }
664 
665  // -->
666  </script>
667  <tr>
668  <td class="dtll">
669  <a href="javascript:void(0);" onClick="Build_File_Link('{$filecount}');" ><img src='/monitor/images/index.gif' border='0' alt='View File'></a>
670  $show_edit_link
671  </td>
672  <td class="dtll">$shortname $help_file</td>
673  <td class="dtll">$file_version_list</td>
674  <td class="dtll">
675  <input type="checkbox" name="delete[]" value="$shortname">Delete
676  $help_del
677  </td>
678  </tr>
679 EOF;
680  /// <td class="dtll"><a href="/monitor/hcudocs$filepath" target="_blank">$shortname</a>$help_file</td>
681  }
682  }
683  }
684  ?>
685  <?php
686 
687  if (count($filelist) == 0 && count($dirlist) == 0) {
688  print <<< EOF
689  <tr>
690  <td class="dtll" colspan="4">
691  No active directories found.
692  </td>
693  </tr>
694 
695  <tr><td colspan="4" class="dtll"><hr></td></tr>
696 EOF;
697  } elseif ((($top_dir == $cpath) && ($top_upload == false))){
698  print <<< EOF
699  <tr><td colspan="4" class="dtll"><hr></td></tr>
700 EOF;
701  } else {
702  $help_delsel = img_help("deleteselected");
703  print <<< EOF
704  <tr><td colspan="4" class="dtll"><hr></td></tr>
705  <tr>
706  <td colspan="3" class="dtll"> &nbsp;</td>
707  <td class="dtll">
708  <input type="submit" name="DFiles" value="Delete Selected" onclick="return check_delete();">
709  $help_delsel
710  </td>
711  </tr>
712 EOF;
713  }
714 
715  // Now print any directories that have NOT been created
716  // then post to this script and allowing them to make the directories
717  // This is the top dir, so use allowed_dir as list
718  // If the allowed_dir and dirlist arrays do not have the same count then list the drop-down
719  // Only allow viewing in the top directory
720  if ((count($dirlist) < count($allowed_dir)) && ($cpath == $top_dir)) {
721  $help_in = img_help("inactive");
722  print <<< EOF
723  <tr>
724  <td class="hdr">&nbsp;</td>
725  <td class="hdr" colspan="3">
726  Inactive Directories $help_in
727  </td>
728  </tr>
729  <tr>
730  <td class="dtll" colspan="4">
731  To activate a private directory click on the folder or the directory name.
732  </td>
733  </tr>
734 EOF;
735  reset($allowed_dir);
736  foreach ($allowed_dir as $key => $value) {
737  if (!in_array($value, $dirlist)) {
738  print <<<EOF
739  <tr>
740  <td class="dtll">
741  <a href="javascript:dir_create('$value','$cdir')" onclick="return confirm_dir('$value');">
742  <img src='/monitor/images/folderin.gif' border='0' alt='Create Directory'></a>
743  </td>
744  <td class="dtll"><a href="javascript:dir_create('$value','$cdir')" onclick="return confirm_dir('$value');">$value</a></td>
745  <td class="dtll" colspan="2">&nbsp;</td>
746  </tr>
747 EOF;
748  // This option was not on the screen so we want to be able to create the directory
749  //print ("<option value=\"$key\">$value</option>\n");
750  }
751  }
752  } elseif ((count($dirlist) >= count($allowed_dir)) && ($cpath == $top_dir)) {
753  print <<< EOF
754  <tr>
755  <td class="hdr">&nbsp;</td>
756  <td class="hdr" colspan="3">
757  Inactive Directories
758  </td>
759  </tr>
760  <tr>
761  <td class="dtll" colspan="4">
762  No inactive directories found.
763  </td>
764  </tr>
765 
766 EOF;
767  }
768  // Now print any directories that have NOT been created
769  // This is not the top level, so get the list of allowed sub-dirs
770  // by using the allow_subs sql.
771  if ($cpath != $top_dir && in_array($cdir, $allowed_dir)){
772  $allowkey=array_search("$cdir",$allowed_dir);
773  $allowsql=$allowed_subs[$allowkey];
774  $rs = db_query($allowsql, $link);
775  if(db_num_rows($rs) > 0) {
776  for ($row=0;list($allow) = db_fetch_array($rs,$row); $row++) {
777  $allowed[]="$allow";
778  }
779 
780  $help_in = img_help("inactive");
781  print <<< EOF
782  <tr>
783  <td class="hdr">&nbsp;</td>
784  <td class="hdr" colspan="3">
785  Inactive Directories $help_in
786  </td>
787  </tr>
788  <tr>
789  <td class="dtll" colspan="4">
790  To activate a private directory click on the folder or the directory name.
791  </td>
792  </tr>
793 EOF;
794  reset($allowed);
795  foreach ($allowed as $key => $value) {
796  if (!in_array($value, $dirlist)) {
797  print <<<EOF
798  <tr>
799  <td class="dtll">
800  <a href="javascript:dir_create('$value','$cdir')" onclick="return confirm_dir('$value');">
801  <img src='/monitor/images/folderin.gif' border='0' alt='Create Directory'></a>
802  </td>
803  <td class="dtll"><a href="javascript:dir_create('$value','$cdir')" onclick="return confirm_dir('$value');">$value</a></td>
804  <td class="dtll" colspan="2">&nbsp;</td>
805  </tr>
806 EOF;
807  // This option was not on the screen so we want to be able to create the directory
808  }
809  }
810  } else {
811  print <<< EOF
812  <tr>
813  <td class="hdr">&nbsp;</td>
814  <td class="hdr" colspan="3">
815  Inactive Directories
816  </td>
817  </tr>
818  <tr>
819  <td class="dtll" colspan="4">
820  No inactive directories found.
821  </td>
822  </tr>
823 EOF;
824  }
825  }
826 
827  if ($cpath == $top_dir || in_array($cdir, $allowed_dir)) {
828  print "<tr><td colspan=\"4\" class=\"dtll\"><hr></td></tr>
829  </table></div>
830  </form>";
831 }
832 }
833 
834 function view_form() {
835  global $dir;
836  global $cspath;
837  global $file;
838  global $self;
839  global $top_dir;
840 
841  $file_path = "$top_dir/$cspath/$file";
842  $form = file($file_path);
843  if (is_array($form)){
844  print implode("", $form);
845  }else{
846  print "Cannot open $file_path";
847  }
848 }
849 
850 function save_form() {
851  global $script_doc, $efile, $msg, $replace, $csub, $delete, $top_dir, $Upload, $DFiles, $err_msg, $cdir, $cspath;
852 
853  // rotate_file ($top_dir . "/" . $efile, $cspath);
854  rotate_file ($efile, $top_dir . "/" . $cspath);
855 
856  // ** Files are rotated thru,
857  // ** NOW I need to open up the file and upload contents of the posted text area into the filename that is entered
858  $filepath_name = $top_dir . "/" . $cspath . "/" . $efile;
859  if ($fp = fopen($filepath_name, "w")) {
860  if (!fwrite ($fp, $script_doc)) {
861  // FAILED
862  } else {
863  // SUCCESS
864  }
865  fclose($fp);
866  } else {
867  // Unable to open file to save
868  }
869 
870 
871 }
872 function post_form() {
873  // Here we will post all the variables from the form and execute as needed
874  global $msg, $upload_file, $upload_file_name, $upload_file_size, $upload_file_type, $replace, $csub, $delete, $top_dir, $Upload, $DFiles, $err_msg, $cdir, $cspath;
875 
876  $cdir = basename(rtrim(($top_dir . ($csub == '' ? "" : "/$csub")),'/'));
877  if ((isset($Upload)) && ($Upload != '')) {
878  // Don't allow a file size of 0 bytes
879  if (!is_uploaded_file($_FILES['upload_file']['tmp_name']) || ($_FILES['upload_file']['size'] < 1)) {
880  switch ($_FILES['upload_file']['error']) {
881  case 0:
882  $up_err = "0: No error, the file was uploaded successfully";
883  break;
884  case 1:
885  $up_err = "1: The upload is larger than the amount allowable by the upload_max_filesize directive in the php.ini";
886  $up_err = "1: The file you tried to upload is just too big. The allowable limit is 40mb.";
887  break;
888  case 2:
889  $up_err = "2: The upload is larger than the MAX_FILE_SIZE directive that was specified via html";
890  $up_err = "2: The file you tried to upload is just too big. The allowable limit is 15mb.";
891  break;
892  case 3:
893  $up_err = "3: The file was only partially uploaded";
894  break;
895  case 3:
896  $up_err = "4: no file was uploaded";
897  break;
898  default:
899  $up_err = "NOT SET";
900  }
901  } else {
902  // The file name will always be that of the file being uploaded
903  $filedir = $top_dir . ($csub == '' ? "" : "/$csub");
904 
905  // strip these characters '/', '\', ';', and ' ' replace with an '_'.
906  $find_ary = array("\\", "/", " ", ";"); // instead of these...
907  $rpl_ary = array("_", "_", "_", "_"); // use the _ character
908  $us_file_name = str_replace($find_ary, $rpl_ary, $_FILES['upload_file']['name']);
909  # make sure we still have a valid file name:
910  if ("$us_file_name" == "") {
911  $up_err = "Error Reported - Invalid Upload to HomeCU Directory";
912  }
913 
914  }
915  if ("$up_err" != "") {
916  $msg = "
917 Upload File Error --\n
918 Client Information \n
919  Client Filename: {$_FILES['upload_file']['name']}\n
920  Client Filesize: {$_FILES['upload_file']['size']}\n
921  Client Filetype: {$_FILES['upload_file']['type']}\n\n
922  Client IP: {$_SERVER['REMOTE_ADDR']}\n\n
923 Web Server Information \n
924  Temp File Name - {$_FILES['upload_file']['tmp_name']}
925  Error Reported - $up_err\n\n
926 
927  ";
928  $notify = new ErrorMail;
929  $notify->line = __LINE__;
930  $notify->file = __FILE__;
931  $notify->callingfunction = __FUNCTION__;
932  $notify->sql = $msg;
933  $notify->mailto = "miki@homecu.net";
934  $notify->subject = "HomeCU Directories upload error";
935  $notify->cu = "$Cu";
936  $notify->SendErr();
937  // IF we got here, the file is NOT an uploaded file report an error
938 
939  // An error may occur here if the file is too large, this can be set in the php.ini file the variable is upload_max_filesize
940  print <<< print_html
941  <center>
942  <br>
943  There was an error uploading the file <b>{$_FILES['upload_file']['name']}</b>.<br>
944  The error reported was: <b>$up_err</b>.<br>
945  Please retry uploading the file.<br>
946  If the problem persists call DMS and report the problem.
947 
948  </center>
949 print_html;
950  } else {
951 
952  // ** Try and create a previous version of the file before uploaded
953 
954  // ** Rotate file for historical
955  rotate_file ($us_file_name, $filedir. "/");
956 
957 
958  $filename = $filedir . "/" . $us_file_name;
959  // move the file into the selected private directory
960  if (!move_uploaded_file($_FILES['upload_file']['tmp_name'], $filename)) {
961  unlink ($_FILES['upload_file']['tmp_name']);
962  // Print error screen -- couldn't move file
963  print <<< html_text
964  <br><br>
965  Uh-oh, couldn't post the file where it belongs. Not sure what happened. Better call DMS.
966 html_text;
967  } else {
968  // File was moved change the mod settings
969  $rc = @chmod($filename, 0644);
970  }
971 }
972 }
973 
974  if ((isset($DFiles)) && ($DFiles != '')) {
975  // Now do any of the other postings, such as delete files
976  if (isset($delete)) {
977  foreach ($delete as $filename) {
978  // Be sure there are not / or \ in the file name
979  $us_file_name = str_replace("/", "", $filename);
980  $us_file_name = str_replace("\\", "", $us_file_name);
981 
982 
983  // If checked then we delete the file
984  $delete_file = $top_dir . ($csub == '' ? "" : "/$csub") . "/" . $us_file_name;
985  //$delete_file = $top_dir . ($csub == '' ? "" : "/$csub") . "/" . $filename;
986  //$delete_file = $top_dir . "/" . $csub . "/" . $filename;
987 
988  if (file_exists($delete_file)) {
989  if (is_file($delete_file)) {
990  // * FILE
991  // ** allow the removal of files that start with "."
992  if (substr($us_file_name, 0, 1) == ".") {
993  if (!@unlink ($delete_file)) {
994  // This will unlink the file from this directory
995  $msg .= "Unable to delete the file! Please try again.<br>";
996  } else {
997  $msg .= "The file '$filename' was deleted successfully.<br>";
998  }
999  } else {
1000  // ** Changed this to now rotate the file through the historical process
1001  // * and not have a "current" file
1002  rotate_file ($us_file_name, $top_dir . "/" . $cspath);
1003  }
1004  } elseif (is_dir($delete_file)) {
1005  // * DIRECTORY
1006  $directory_empty = TRUE;
1007  $directory = dir($delete_file);
1008  while (FALSE !== ($item = $directory->read())) {
1009  // If an item is not "." or "..", dir is not empty
1010  if ($item != '.' && $item != '..') {
1011  $directory_empty = FALSE;
1012  break;
1013  }
1014  }
1015  $directory->close();
1016  if(($directory_empty == TRUE) && ( @rmdir ($delete_file))) {
1017  $msg .= "The folder '$filename' was deleted successfully.<br>";
1018  } else {
1019  $msg .= "Unable to delete folder '$filename'! Please be sure the folder is empty.<br>";
1020  }
1021  }
1022  }
1023  }
1024  }
1025  }
1026  }
1027 
1028 function restore_file() {
1029 
1030  global $self, $efile, $msg, $replace, $csub, $delete, $top_dir, $Upload, $DFiles, $err_msg, $cdir, $cspath, $HCUDocs_MaxPreviousVersion;
1031 
1032  // Technically.. I should only be able to restore historical files, I am trying to NOT allow current file to be restored.. makes little sense..
1033  // So what I need to do is get the original filename from the restored file
1034 
1035 
1036 
1037  $restore_file_tmpname = "";
1038  $restore_file_basename = $efile; // start with current name
1039 
1040  // * trim leading "."
1041  if (substr($restore_file_basename, 0, 1) == ".") {
1042  $restore_file_basename = substr($restore_file_basename, 1);
1043  }
1044  // * Now truncate the end where the .X may exist
1045  $restore_file_basename = substr($restore_file_basename, 0, strrpos($restore_file_basename, "."));
1046 
1047  $restore_file_tmpname = "." . $restore_file_basename . "." . ($HCUDocs_MaxPreviousVersion + 1);
1048 
1049  $restore_file_directory = $top_dir . "/" . $cspath . "/";
1050  // This is what I was thinking
1051  if (is_file($restore_file_directory . $efile)) {
1052 
1053  // Rename the file we are going to restore to .{HCUDocMaximum + 1}
1054 // print "<Br> RENAME - " . $restore_file_directory . $efile . " to " . $restore_file_directory . $restore_file_tmpname;
1055  if (@copy($restore_file_directory . $efile, $restore_file_directory . $restore_file_tmpname)) {
1056 
1057  // Next call the Rotate File Function .. Rotate all through
1058  rotate_file ($restore_file_basename, $restore_file_directory);
1059 // print "<br> ROTATE FILE file: " . $restore_file_basename . " dir: " . $restore_file_directory;
1060 
1061  // Rename the .{HCUDocMaximum + 1} to current file
1062  @rename($restore_file_directory . $restore_file_tmpname, $restore_file_directory . $restore_file_basename);
1063 // print "<br>RENAME tmp - " . $restore_file_directory . $restore_file_tmpname . " to " . $restore_file_directory . $restore_file_basename;
1064  }
1065 
1066 
1067  } // DO NOTHING IF FILE NOT FOUND
1068 
1069 }
1070 function edit_form() {
1071 
1072  global $self, $efile, $msg, $replace, $csub, $delete, $top_dir, $Upload, $DFiles, $err_msg, $cdir, $cspath, $act;
1073 
1074 
1075  // Decide FileName
1076 
1077 // print "efile - $efile<bR>csub - $csub<br>cdir - $cdir<br>cspath - $cspath<br>";
1078 
1079  $folder_path = ($cspath == "" ? "&nbsp;" : "Folder: &nbsp; <a href='$self?cdir=$cdir&csub=$cspath'>$cspath</a>");
1080 
1081  if ($efile == "") {
1082  // * NEW FILE
1083  $folder_path .= " / NEW FILE";
1084  $filename_formedit = "<input type=\"text\" name=\"efile_new\" value=\"\">.html";
1085  } else {
1086  $folder_path .= " / $efile";
1087  }
1088  print <<< print_html
1089  <html><head><title>HCU_Docs</title>
1090  <LINK REL=stylesheet HREF='/monitor/css/monitor.css' TYPE='text/css'>
1091  </head>
1092  <body>
1093  <form method="post" action="$self" enctype="multipart/form-data">
1094  <input type="hidden" name="action" value="upload">
1095  <input type="hidden" name="csub" value="$cspath">
1096  <input type="hidden" name="cdir" value="$cdir">
1097  <input type="hidden" name="cpath" value="$cpath">
1098  <br><div align=center><table width=95% border=0 cellspacing=0 cellpadding=4>
1099  <tr><td colspan=4 class="bar" align=center>HomeCU Documents</td></tr>
1100  <tr>
1101  <td class="hdrl">&nbsp;</td>
1102  <td class="hdrl"><a href="{$infourl}/hcuadm/cuilist.prg" target="_parent">Credit Union List</a></td>
1103  <td colspan=2 class="hdrl">$folder_path $filename_formedit</td>
1104  </tr>
1105  <tr>
1106  <td colspan=4 class="dtl" align="center">
1107 
1108 print_html;
1109 
1110  $filename_formedit = "";
1111  $filenew = (strtoupper($act) == "NEW");
1112 
1113  if ($filenew) {
1114  // ** Possibly create a new blank file for this, maybe for NEW require a name for the file
1115 
1116  $efile = "";
1117  } else {
1118  // Read the file and send the information to the text area
1119  $cu_file = $top_dir . "/" . $csub . "/" . $efile;
1120  $file_opened = false;
1121  if (file_exists($cu_file)) {
1122  if ($fp = fopen($cu_file, "r")) {
1123  $file_opened = true;
1124  $contents = fread($fp, filesize($cu_file));
1125  }
1126  }
1127 
1128  // $filename_formedit = "$efile<input type=\"hidden\" name=\"efile\" value=\"$efile\">";
1129  }
1130 
1131 
1132  // ** For .html extended files -- I want to include the TinyMCE insert
1133  $textarea_TinyMCE = "";
1134 
1135  if ((strtolower(substr($cu_file, (strrpos($cu_file, ".") === false ? strlen($cu_file) : strrpos($cu_file, ".")))) == ".html") || $filenew) {
1136  $textarea_TinyMCE = <<< set_TinyMCE
1137  <script type="text/javascript" src="/monitor/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
1138 
1139  <script type="text/javascript">
1140  tinyMCE.init({
1141  // General options
1142  mode : "textareas",
1143  theme : "advanced",
1144  plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
1145 
1146  // Theme options
1147  theme_advanced_buttons1 : "save, bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
1148  theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
1149  theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
1150  theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,blockquote,pagebreak,|,insertfile,insertimage",
1151  theme_advanced_toolbar_location : "top",
1152  theme_advanced_toolbar_align : "left",
1153  theme_advanced_statusbar_location : "bottom",
1154  theme_advanced_resizing : true,
1155 
1156  // Skin options
1157  skin : "o2k7",
1158  skin_variant : "silver",
1159  save_enablewhendirty : true,
1160  save_onsavecallback : "savefile"
1161 
1162  // Example content CSS (should be your site CSS)
1163 // content_css : "css/example.css",
1164 
1165  });
1166  function savefile () {
1167 
1168  // * *Be sure the filename was enterred if this is NEW
1169  // if it is new, then put the filename + .html into the efile hidden field..
1170  // This becomes the new filename
1171  var objfilename = document.forms[0].elements['efile_new'];
1172  var objsavedfilename = document.forms[0].elements['efile'];
1173  var isnewdoc = objfilename != null;
1174  var savefileok = true;
1175 
1176  if (isnewdoc) {
1177  // ** Be sure they have entered a filename for the form
1178  if (objfilename.value == "") {
1179  window.alert ("Enter file name for this new file.");
1180  savefileok = false;
1181  } else {
1182  // *Save the file name to be saved
1183  objsavedfilename.value = objfilename.value + ".html";
1184  }
1185  }
1186 
1187  // *FORCE THE SUBMIT
1188  if (savefileok) {
1189  document.forms[0].submit();
1190  }
1191  }
1192  </script>
1193 set_TinyMCE;
1194  }
1195 
1196 
1197 
1198  if (($file_opened == true && !$filenew) || ($filenew)) {
1199  $showcontents=htmlspecialchars($contents);
1200  print <<< print_html
1201 
1202  $textarea_TinyMCE
1203 
1204  <script language="javascript">
1205  <!--
1206  var win=null;
1207  function Preview() {
1208  win = window.open("","htmlWin","scrollbars=1,menubar=1,status=1")
1209  //win.document.write("<BASE HREF='" + document.Tag.baseHref.value + "'>")
1210  win.document.write("<P>")
1211  win.document.write(document.preview.script_doc.value)
1212  win.document.write("</P>")
1213  }
1214  // -->
1215  </script>
1216  <form name="preview" action="$self" method="post">
1217  <input type="hidden" name="action" value="saveedit">
1218  <input type="hidden" name="csub" value="$cspath">
1219  <input type="hidden" name="cdir" value="$cdir">
1220  <input type="hidden" name="cpath" value="$cpath>">
1221  <input type="hidden" name="efile" value="$efile">
1222  <br>
1223  <textarea name="script_doc" rows=50 cols=90>$showcontents</textarea>
1224  </form>
1225 print_html;
1226  } else {
1227  // Problem opening the file
1228  print '
1229  <table align=center border=0 cellpadding=0 cellspacing=0 width="60%" class="dmsbg"><tr><td>
1230  <table border=0 cellpadding=0 cellspacing=0 width="100%">
1231  <tr>
1232  <td class="dtl">
1233  An incorrect selection was made, please go back to the <a href="' . $self . '">menu</a><br>
1234  and select again.
1235  </td>
1236  </tr>
1237  </table>
1238  </td></tr></table>';
1239  }
1240 
1241  print <<< print_html
1242  </td>
1243  </tr>
1244  </table>
1245  </form></body>
1246 
1247 print_html;
1248  }
1249 
1250 function rotate_file($HCUDocs_Filename, $HCUDocs_Directory) {
1251 
1252 // ** This function will rotate the current file along with the max number of 'hidden' previous versions
1253 // * and rotate through {max previous version} - 1 renamed to {max previous version} and finally current name
1254 // * renamed to {previous version}.1
1255 
1256  global $cpath, $top_dir, $HCUDocs_MaxPreviousVersion;
1257 
1258  // global $msg, $upload_file, $upload_file_name, $upload_file_size, $upload_file_type, $replace, $csub, $delete, $top_dir, $Upload, $DFiles, $err_msg, $cdir, $cspath;
1259 
1260  // $cdir = basename(rtrim(($top_dir . ($csub == '' ? "" : "/$csub")),'/'));
1261 
1262  // Process will be as follows
1263  // * - Delete {Filename}.{MaxVersions}
1264  // * - Loop through remaining previous version, renaming extension to be Numeric + 1
1265  // * - Rename {Filename} to {Filename}.1
1266 
1267 
1268  // $HCUDocs_Filename = "";
1269  // $HCUDocs_Directory = "";
1270  // $HCUDocs_MaxPreviousVersion = 5;
1271 
1272  // ** Check to see if Directory has a "/" at the end.. If NOT , then add it
1273  $HCUDocs_Directory .= (substr($HCUDocs_Directory, -1) != "/" ? "/" : "");
1274 
1275 
1276  $LoopFilename = "";
1277  $LoopFilename = "$HCUDocs_Directory" . "." . $HCUDocs_Filename . ".$HCUDocs_MaxPreviousVersion";
1278  // * First look for the MAX previous version of file and delete if found
1279 /*
1280  if (file_exists($LoopFilename)) {
1281  if (is_file($Loopfilename)) {
1282  if (!@unlink ($delete_file)) {
1283  // NOT ABLE TO DELETE FILE
1284  } else {
1285  // FILE DELETED
1286  }
1287  }
1288  }
1289 */
1290 
1291 
1292 
1293  // * NOW LOOP THROUGH REMAINING Version Numbers, reording {Max -1 } to {Max}, {Max - 2} to {Max - 1}, etc
1294  for ($idxPreVersion = $HCUDocs_MaxPreviousVersion - 1; $idxPreVersion > 0; $idxPreVersion--) {
1295  $LoopFilename = "$HCUDocs_Directory" . "." . $HCUDocs_Filename . ".$idxPreVersion";
1296  $LoopNewName = "$HCUDocs_Directory" . "." . $HCUDocs_Filename . "." . ($idxPreVersion + 1);
1297  if (file_exists($LoopFilename)) {
1298  // ** File exists.. Rename to be (idxPreVersion)
1299  if (! @rename($LoopFilename, $LoopNewName)) {
1300  // file could NOT be renamed
1301  }
1302  }
1303  }
1304 
1305 
1306  // ** Rename the original file
1307  $LoopFilename = $HCUDocs_Directory . $HCUDocs_Filename;
1308  $LoopNewName = $HCUDocs_Directory . "." . $HCUDocs_Filename . ".1";
1309 
1310  // ** ONLY Rename if the original file it really exists
1311  if (file_exists($LoopFilename)) {
1312  if (! @rename($LoopFilename, $LoopNewName)) {
1313 
1314  // ** COULD NOT RENAME
1315  }
1316  }
1317 
1318 
1319 
1320  // ** NOW we should have the hidden files setup... ready to either upload the new file
1321  // ** Or save a file
1322 
1323 
1324 }
1325 
1326 ?>