Statistiques
| Branche: | Révision :

root / src / raw_dir.MVC.php @ d072e29c

Historique | Voir | Annoter | Télécharger (2,75 ko)

1 d072e29c Florent Chuffart
<?php
2 d072e29c Florent Chuffart
$q = "SELECT * FROM $this->tb WHERE `$this->key`='$this->rec'";
3 d072e29c Florent Chuffart
// echo "$q";
4 d072e29c Florent Chuffart
// echo "<pre>";
5 d072e29c Florent Chuffart
// print_r($this);
6 d072e29c Florent Chuffart
// echo "</pre>";
7 d072e29c Florent Chuffart
$all = $this->myQuery($q);
8 d072e29c Florent Chuffart
$current_object = mysql_fetch_object($all);
9 d072e29c Florent Chuffart
10 d072e29c Florent Chuffart
if ($current_object) {
11 d072e29c Florent Chuffart
  $current_class_raw_dir = "raw_dirs/$this->tb";
12 d072e29c Florent Chuffart
  $current_entry_raw_dir = "$current_class_raw_dir/$this->rec/";
13 d072e29c Florent Chuffart
  if ($_REQUEST["action"] == "ADD_RAW_FILE") {
14 d072e29c Florent Chuffart
    if (!file_exists($current_class_raw_dir)) {
15 d072e29c Florent Chuffart
      mkdir($current_class_raw_dir);
16 d072e29c Florent Chuffart
    }
17 d072e29c Florent Chuffart
    $userfile = $_FILES["userfile"]["tmp_name"];
18 d072e29c Florent Chuffart
    $userfile_name = $_FILES["userfile"]["name"];
19 d072e29c Florent Chuffart
    $ext = strtolower(array_pop(explode("\.", $userfile_name)));
20 d072e29c Florent Chuffart
    if (in_array($ext, array("php", "php5", "cgi"))) {
21 d072e29c Florent Chuffart
      if(file_exists($userfile)) {
22 d072e29c Florent Chuffart
        unlink($userfile);
23 d072e29c Florent Chuffart
      }
24 d072e29c Florent Chuffart
      exit("ERROR 1, your file CAN NOT have this extension.<br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>");
25 d072e29c Florent Chuffart
    }
26 d072e29c Florent Chuffart
    if (!file_exists($current_entry_raw_dir)) {
27 d072e29c Florent Chuffart
      mkdir($current_entry_raw_dir);
28 d072e29c Florent Chuffart
    }
29 d072e29c Florent Chuffart
    $dest_filename = str_replace(" ","_",substr($userfile_name, 0, strlen($userfile_name)));
30 d072e29c Florent Chuffart
    $dest_filepath = $current_entry_raw_dir . $dest_filename;
31 d072e29c Florent Chuffart
    if (file_exists($dest_filepath)) {
32 d072e29c Florent Chuffart
      if (file_exists($userfile)) {
33 d072e29c Florent Chuffart
        unlink($userfile);
34 d072e29c Florent Chuffart
      }
35 d072e29c Florent Chuffart
      exit("ERROR 2, this filename is already used. <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>");
36 d072e29c Florent Chuffart
    }
37 d072e29c Florent Chuffart
    if (!copy($userfile, $dest_filepath)){
38 d072e29c Florent Chuffart
      if (file_exists($userfile)) {
39 d072e29c Florent Chuffart
        unlink($userfile);
40 d072e29c Florent Chuffart
      }
41 d072e29c Florent Chuffart
      exit("ERROR 3, problem copying file. <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>");
42 d072e29c Florent Chuffart
    }
43 d072e29c Florent Chuffart
    if(file_exists($userfile)) {
44 d072e29c Florent Chuffart
      unlink($userfile);
45 d072e29c Florent Chuffart
    }
46 d072e29c Florent Chuffart
  }
47 d072e29c Florent Chuffart
  /*
48 d072e29c Florent Chuffart
  * VIEW
49 d072e29c Florent Chuffart
  */
50 d072e29c Florent Chuffart
  $in_edit_mode = $_REQUEST["PME_sys_operation"] == "Change" || $_REQUEST["PME_sys_operation"] == "PME_op_Change";
51 d072e29c Florent Chuffart
52 d072e29c Florent Chuffart
  if ($in_edit_mode) {  
53 d072e29c Florent Chuffart
    $raw_dir_form = <<<EOD
54 d072e29c Florent Chuffart
  <form action='' method='post' enctype='multipart/form-data'>
55 d072e29c Florent Chuffart
    Upload a file to the raw directory of this entry: 
56 d072e29c Florent Chuffart
    <input type='hidden' name='PME_sys_operation' value='PME_op_Change'/>
57 d072e29c Florent Chuffart
    <input type='hidden' name='PME_sys_rec' value='$this->rec'/>
58 d072e29c Florent Chuffart
    <input type='hidden' name='action' value='ADD_RAW_FILE'/>
59 d072e29c Florent Chuffart
    <input name='userfile' type='file' size='10'/>
60 d072e29c Florent Chuffart
    <input type='button' name='send' value='Upload' onclick='return this.form.submit();'/>
61 d072e29c Florent Chuffart
  </form>
62 d072e29c Florent Chuffart
EOD;
63 d072e29c Florent Chuffart
  }
64 d072e29c Florent Chuffart
65 d072e29c Florent Chuffart
  if (file_exists($current_entry_raw_dir)) {
66 d072e29c Florent Chuffart
    $fp = fopen(LABSTOCK_SERVER . $current_entry_raw_dir, 'r', false);
67 d072e29c Florent Chuffart
    $raw_dir_content = preg_replace("/a href=\"/", "a href=\"" . LABSTOCK_SERVER . $current_entry_raw_dir, stream_get_contents($fp));
68 d072e29c Florent Chuffart
    preg_match("'<table>(.*?)</table>'si", $raw_dir_content, $match);
69 d072e29c Florent Chuffart
    // print_r($match);
70 d072e29c Florent Chuffart
    $raw_dir_frame = "<table>" . $match[1] . "</table>";
71 d072e29c Florent Chuffart
  }
72 d072e29c Florent Chuffart
}
73 d072e29c Florent Chuffart
74 d072e29c Florent Chuffart
$to_be_post_list_content .= <<<EOD
75 d072e29c Florent Chuffart
  $raw_dir_form
76 d072e29c Florent Chuffart
  $raw_dir_frame
77 d072e29c Florent Chuffart
  <hr/>
78 d072e29c Florent Chuffart
EOD;
79 d072e29c Florent Chuffart
?>