3 * Copyright (C) 2003-2004 Polytechnique.org
4 * http://opensource.polytechnique.org/
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 require_once 'Barrel.php';
23 require_once 'Barrel/Options.php';
26 /** This class provides a viewer/editor for Diogenes's barrels
28 class Diogenes_Barrel_Editor
30 /** Is this barrel editor read only (i.e. a list) ? */
34 /** Adds a barrel to the list of barrels we display.
39 function addBarrel(&$page, $barrel)
44 if (!$this->readonly
) {
45 array_push($actions, array(__("edit"), "?action=edit&target={$barrel['alias']}"));
47 array_push($actions, array(__("admin"), $page->urlBarrel($barrel['alias'],$barrel['vhost'],"admin/")));
49 if (!$this->readonly
) {
50 $flags = new flagset($barrel['flags']);
51 if ($flags->hasFlag('plug')) {
52 array_push($actions, array(__("plugins"), "plugins?plug_barrel={$barrel['alias']}"));
54 array_push($actions, array(__("delete"), "javascript:del('{$barrel['alias']}');"));
58 $page->append('sites',array(
59 'alias' => $barrel['alias'],
60 'title' => array( $barrel['title'], $page->urlBarrel($barrel['alias'],$barrel['vhost']) ),
61 'description' => $barrel['description'],
62 'actions' => $actions )
67 /** Run the Barrel editor.
72 function run(&$page, $outputvar = '')
76 $page->assign('post',$page->script_self());
78 $action = isset($_REQUEST["action"]) ?
$_REQUEST["action"] : "list";
81 if ($this->readonly
) die("Sorry, this barrel editor is read-only.");
82 if (isset($_REQUEST["target"])) {
83 Diogenes_Barrel
::create($_REQUEST["target"], $page);
88 if ($this->readonly
) die("Sorry, this barrel editor is read-only.");
89 if (isset($_REQUEST["target"])) {
91 $flags = isset($_REQUEST['flags']) ?
implode(",",array_values($_REQUEST['flags'])) : "";
92 $globals->db
->query("update diogenes_site set vhost='{$_REQUEST['vhost']}',flags='$flags' where alias='{$_REQUEST['target']}'");
93 $opts = new Diogenes_Barrel_Options($_REQUEST['target']);
94 $opts->updateOption('description', $_REQUEST['description']);
95 $opts->updateOption('title', $_REQUEST['title']);
96 $opts->updateOption('keywords', $_REQUEST['keywords']);
101 if ($this->readonly
) die("Sorry, this barrel editor is read-only.");
102 if (isset($_REQUEST["target"])) {
103 $res = $globals->db
->query("select alias,vhost,flags from diogenes_site where alias='{$_REQUEST['target']}'");
104 if (!list($target,$vhost,$flags) = mysql_fetch_row($res)) {
105 $page->info("Could not find specified site!");
109 mysql_free_result($res);
110 $page->assign('target',$target);
111 $page->assign('v_vhost',$vhost);
112 $flags = new flagset($flags);
113 $flag_opts = array('tpl' => __("custom templates"), 'plug' => __("plugins"));
114 $page->assign('v_flag_opts', $flag_opts);
115 foreach($flag_opts as $key=>$val) {
116 if ($flags->hasFlag($key))
117 $page->append('v_flags', $key);
119 $opts = new Diogenes_Barrel_Options($target);
120 $page->assign('v_desc',$opts->description
);
121 $page->assign('v_title',$opts->title
);
122 $page->assign('v_keywords',$opts->keywords
);
127 if ($this->readonly
) die("Sorry, this barrel editor is read-only.");
128 if (isset($_REQUEST["target"])) {
129 Diogenes_Barrel
::destroy($_REQUEST["target"], $page);
137 if ($action == "list") {
138 $res = $globals->db
->query("select s.alias,s.vhost,s.flags,o.name,o.value from diogenes_site as s left join diogenes_option as o on s.alias=o.barrel order by s.alias");
139 $barrel = array('alias' => '');
141 while (list($s_alias,$s_vhost,$s_flags,$o_name,$o_value) = mysql_fetch_row($res)) {
142 if ($s_alias != $barrel['alias']) {
143 if ($barrel['alias']) $this->addBarrel($page, $barrel);
144 $barrel = array('alias' => $s_alias,'vhost' => $s_vhost, 'flags' => $s_flags, 'title' => '','description' => '');
146 $barrel[$o_name] = $o_value;
148 mysql_free_result($res);
149 if ($barrel['alias']) $this->addBarrel($page, $barrel);
150 } // $action == "list"
153 $page->assign('action',$action);
154 $page->assign('readonly', $this->readonly
);
158 $page->assign('msg_alias',__("alias"));
159 $page->assign('msg_title',__("site"));
160 $page->assign('msg_desc',__("description"));
161 $page->assign('msg_keywords',__("keywords"));
162 $page->assign('msg_create',__("Create a new site"));
163 $page->assign('msg_create_note',__("The site alias may only contain letters, numbers and underscores."));
164 $page->assign('msg_submit',__("Submit"));
165 $page->assign('msg_no_barrels', __("no barrels available"));
166 $page->assign('msg_vhost',__("vhost (see note)"));
167 $page->assign('msg_vhost_note', __("<b>vhost note</b>: If you intend to serve this site from a virtualhost, you should enter the name of the virtualhost in this field."));
168 $page->assign('msg_flags',__("flags"));
170 // if requested, assign the content to be displayed
171 if (!empty($outputvar)) {
172 $page->assign($outputvar, $page->fetch('barrel-editor.tpl'));