[1] | 1 | <?php |
---|
| 2 | |
---|
| 3 | class data_boxes extends data |
---|
| 4 | { |
---|
| 5 | |
---|
| 6 | # ---------------------------------------------------------------------------------------- |
---|
| 7 | # emplacements de blocs |
---|
| 8 | # |
---|
| 9 | |
---|
| 10 | function box_emplacements() |
---|
| 11 | { $emplacements = array(); |
---|
| 12 | if($this->env->out_file_exists("emplacements.xml")) |
---|
| 13 | { $emplacements_config = simplexml_load_file($this->env->out_file("emplacements.xml")); |
---|
| 14 | foreach($emplacements_config as $emplacement) |
---|
| 15 | { $emplacements[utf8_decode($emplacement->id)] = array(); |
---|
| 16 | foreach($emplacement as $emplacement_key => $emplacement_value) |
---|
| 17 | { $emplacements[utf8_decode($emplacement->id)][utf8_decode($emplacement_key)] = utf8_decode($emplacement_value); |
---|
| 18 | } |
---|
| 19 | } |
---|
| 20 | } |
---|
| 21 | else $emplacements = false; |
---|
| 22 | return $emplacements; |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | # ---------------------------------------------------------------------------------------- |
---|
| 26 | # blocs |
---|
| 27 | # |
---|
| 28 | |
---|
| 29 | function box_files() |
---|
| 30 | { $box_files = array(); |
---|
| 31 | $boxes_dir = $this->env->path("out")."boxes/"; |
---|
| 32 | if(is_dir($boxes_dir)) |
---|
| 33 | { if($dh = opendir($boxes_dir)) |
---|
| 34 | { while(($file = readdir($dh)) !== false) |
---|
| 35 | { if(substr($file, 0, 1) != "." && substr($file, -4) == ".php") |
---|
| 36 | { $box_files[] = $file; |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | } |
---|
| 40 | closedir($dh); |
---|
| 41 | } |
---|
| 42 | return $box_files; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | function boxes($start = 0, $emplacement = null, $public = null) |
---|
| 46 | { $boxes = array(); |
---|
| 47 | try |
---|
| 48 | { $boxes = array("list" => array(), "total" => 0); |
---|
| 49 | $query = |
---|
| 50 | "SELECT count(*) as n" |
---|
| 51 | ." FROM #--boxes" |
---|
| 52 | .(isset($emplacement) ? " WHERE #--boxes.emplacement".($emplacement ? "=".$this->eq($emplacement) : " IS NULL") : "") |
---|
| 53 | .(isset($public) ? (isset($emplacement) ? " AND" : " WHERE")." public=".($public ? "1" : "0") : ""); |
---|
| 54 | $rst = $this->sql->query($query); |
---|
| 55 | if($v_rst = $this->sql->fetch_assoc($rst)) $boxes["total"] = $v_rst["n"]; |
---|
| 56 | $this->sql->free_result($rst); |
---|
| 57 | if($boxes["total"] > 0) |
---|
| 58 | { $query = |
---|
| 59 | "SELECT #--boxes.*" |
---|
| 60 | .", #--pun_users.username as auteur" |
---|
| 61 | ." FROM #--pun_users, #--boxes" |
---|
| 62 | ." WHERE #--boxes.auteur_creation=#--pun_users.id" |
---|
| 63 | .(isset($emplacement) ? " AND #--boxes.emplacement".($emplacement ? "=".$this->eq($emplacement) : " IS NULL") : "") |
---|
| 64 | .(isset($public) ? " AND public=".($public ? "1" : "0") : "") |
---|
| 65 | ." ORDER BY #--boxes.ordre"; |
---|
| 66 | $rst = $this->sql->query($query); |
---|
| 67 | while($v_rst = $this->sql->fetch_assoc($rst)) $boxes["list"][$v_rst["id"]] = $v_rst; |
---|
| 68 | $this->sql->free_result($rst); |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | catch(Exception $_e) { $boxes = false; } |
---|
| 72 | return $boxes; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | function box($id) |
---|
| 76 | { $box = array(); |
---|
| 77 | try |
---|
| 78 | { $query = |
---|
| 79 | "SELECT #--boxes.*" |
---|
| 80 | .", #--pun_users.username as auteur" |
---|
| 81 | ." FROM #--pun_users, #--boxes" |
---|
| 82 | ." WHERE #--boxes.auteur_creation=#--pun_users.id" |
---|
| 83 | ." AND #--boxes.id=".$this->eq($id); |
---|
| 84 | $rst = $this->sql->query($query); |
---|
| 85 | if($v_rst = $this->sql->fetch_assoc($rst)) $box = $v_rst; |
---|
| 86 | } |
---|
| 87 | catch(Exception $_e) { $box = false; } |
---|
| 88 | return $box; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | function add_box($titre, $public, $nom, $emplacement, $fichier, $contenu, $user) |
---|
| 92 | { try |
---|
| 93 | { $query = |
---|
| 94 | "INSERT INTO #--boxes" |
---|
| 95 | ."(nom, emplacement, titre, fichier, contenu, auteur_creation, date_creation, public) VALUES" |
---|
| 96 | ."( ".$this->eq($nom) |
---|
| 97 | .", ".$this->eq($emplacement) |
---|
| 98 | .", ".$this->eq($titre) |
---|
| 99 | .", ".$this->eq($fichier) |
---|
| 100 | .", ".$this->eq($contenu) |
---|
| 101 | .", ".$this->eq($user) |
---|
| 102 | .", NOW()" |
---|
| 103 | .", ".$this->eq($public) |
---|
| 104 | .")"; |
---|
| 105 | $this->sql->query($query); |
---|
| 106 | } |
---|
| 107 | catch(Exception $_e) { return false; } |
---|
| 108 | return true; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | function set_box($id, $titre, $public, $nom, $emplacement, $fichier, $contenu, $user) |
---|
| 112 | { try |
---|
| 113 | { $query = |
---|
| 114 | "UPDATE #--boxes SET" |
---|
| 115 | ." nom=".$this->eq($nom) |
---|
| 116 | .", emplacement=".$this->eq($emplacement) |
---|
| 117 | .", titre=".$this->eq($titre) |
---|
| 118 | .", fichier=".$this->eq($fichier) |
---|
| 119 | .", contenu=".$this->eq($contenu) |
---|
| 120 | .", auteur_modification=".$this->eq($user) |
---|
| 121 | .", date_modification=NOW()" |
---|
| 122 | .", public=".$this->eq($public) |
---|
| 123 | ." WHERE id=".$this->eq($id); |
---|
| 124 | $this->sql->query($query); |
---|
| 125 | } |
---|
| 126 | catch(Exception $_e) { return false; } |
---|
| 127 | return true; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | function set_box_ordre($id, $ordre) |
---|
| 131 | { try |
---|
| 132 | { $query = |
---|
| 133 | "UPDATE #--boxes SET" |
---|
| 134 | ." ordre=".$this->eq($ordre) |
---|
| 135 | ." WHERE id=".$this->eq($id); |
---|
| 136 | $this->sql->query($query); |
---|
| 137 | } |
---|
| 138 | catch(Exception $_e) { return false; } |
---|
| 139 | return true; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | function del_box($id) |
---|
| 143 | { try |
---|
| 144 | { $query = |
---|
| 145 | "DELETE FROM #--boxes" |
---|
| 146 | ." WHERE id=".$this->eq($id); |
---|
| 147 | $this->sql->query($query); |
---|
| 148 | } |
---|
| 149 | catch(Exception $_e) { return false; } |
---|
| 150 | return true; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | ?> |
---|