Editor.php

00001 <?php
00002 /*
00003  * Copyright (C) 2003-2004 Polytechnique.org
00004  * http://opensource.polytechnique.org/
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 
00022 require_once 'Barrel.php';
00023 require_once 'Barrel/Options.php';
00024 
00025 
00028 class Diogenes_Barrel_Editor
00029 {
00031   var $readonly = 0;
00032   
00033 
00039   function addBarrel(&$page, $barrel)
00040   {
00041     global $page;
00042     
00043     $actions = array();
00044     if (!$this->readonly) {
00045        array_push($actions, array(__("edit"), "?action=edit&amp;target={$barrel['alias']}"));
00046      }       
00047      array_push($actions, array(__("admin"), $page->urlBarrel($barrel['alias'],$barrel['vhost'],"admin/")));
00048      
00049     if (!$this->readonly) {     
00050       $flags = new flagset($barrel['flags']);
00051       if ($flags->hasFlag('plug')) {
00052         array_push($actions, array(__("plugins"), "plugins?plug_barrel={$barrel['alias']}"));                   
00053       }
00054       array_push($actions, array(__("delete"), "javascript:del('{$barrel['alias']}');"));
00055     }    
00056     
00057     
00058     $page->append('sites',array(
00059       'alias' => $barrel['alias'],
00060       'title' => array( $barrel['title'], $page->urlBarrel($barrel['alias'],$barrel['vhost']) ),
00061       'description' => $barrel['description'],
00062       'actions' => $actions )
00063     );
00064   }
00065 
00066 
00072   function run(&$page, $outputvar = '')
00073   {
00074     global $globals;
00075     
00076     $page->assign('post',$page->script_self());
00077     
00078     $action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : "list";
00079     switch($action) {
00080       case "create":
00081         if ($this->readonly) die("Sorry, this barrel editor is read-only.");
00082         if (isset($_REQUEST["target"])) {
00083           Diogenes_Barrel::create($_REQUEST["target"], $page);
00084         }
00085         $action="list";
00086         break;
00087       case "update":
00088         if ($this->readonly) die("Sorry, this barrel editor is read-only.");
00089         if (isset($_REQUEST["target"])) {
00090           // build flags
00091           $flags = isset($_REQUEST['flags']) ? implode(",",array_values($_REQUEST['flags'])) : "";
00092           $globals->db->query("update diogenes_site set vhost='{$_REQUEST['vhost']}',flags='$flags' where alias='{$_REQUEST['target']}'");
00093           $opts = new Diogenes_Barrel_Options($_REQUEST['target']);
00094           $opts->updateOption('description', $_REQUEST['description']);
00095           $opts->updateOption('title', $_REQUEST['title']);
00096           $opts->updateOption('keywords', $_REQUEST['keywords']);
00097         }
00098         $action="list";
00099         break;
00100       case "edit":
00101         if ($this->readonly) die("Sorry, this barrel editor is read-only.");
00102         if (isset($_REQUEST["target"])) {
00103           $res = $globals->db->query("select alias,vhost,flags from diogenes_site where alias='{$_REQUEST['target']}'");
00104           if (!list($target,$vhost,$flags) = mysql_fetch_row($res)) {
00105             $page->info("Could not find specified site!");
00106             $action = "list";
00107             break;
00108           }
00109           mysql_free_result($res);
00110           $page->assign('target',$target);
00111           $page->assign('v_vhost',$vhost);
00112           $flags = new flagset($flags);
00113           $flag_opts = array('tpl' => __("custom templates"), 'plug' => __("plugins"));
00114           $page->assign('v_flag_opts', $flag_opts);
00115           foreach($flag_opts as $key=>$val) {
00116             if ($flags->hasFlag($key))
00117               $page->append('v_flags', $key);
00118           }
00119           $opts = new Diogenes_Barrel_Options($target);
00120           $page->assign('v_desc',$opts->description);
00121           $page->assign('v_title',$opts->title);
00122           $page->assign('v_keywords',$opts->keywords);
00123     
00124         }
00125         break;
00126       case "delete":
00127         if ($this->readonly) die("Sorry, this barrel editor is read-only.");
00128         if (isset($_REQUEST["target"])) {
00129           Diogenes_Barrel::destroy($_REQUEST["target"], $page);
00130         }
00131         $action="list";
00132         break;
00133       default:
00134         $action="list";
00135     }
00136     
00137     if ($action == "list") {
00138       $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");
00139       $barrel = array('alias' => '');
00140     
00141       while (list($s_alias,$s_vhost,$s_flags,$o_name,$o_value) = mysql_fetch_row($res)) {
00142         if ($s_alias != $barrel['alias']) {
00143           if ($barrel['alias']) $this->addBarrel($page, $barrel);  
00144           $barrel = array('alias' => $s_alias,'vhost' => $s_vhost, 'flags' => $s_flags, 'title' => '','description' => '');    
00145         }
00146         $barrel[$o_name] = $o_value;  
00147       }
00148       mysql_free_result($res);
00149       if ($barrel['alias']) $this->addBarrel($page, $barrel);  
00150     } // $action == "list"
00151     
00152     // values
00153     $page->assign('action',$action);
00154     $page->assign('readonly', $this->readonly);
00155     
00156     
00157     // translations 
00158     $page->assign('msg_alias',__("alias"));
00159     $page->assign('msg_title',__("site"));
00160     $page->assign('msg_desc',__("description"));
00161     $page->assign('msg_keywords',__("keywords"));
00162     $page->assign('msg_create',__("Create a new site"));
00163     $page->assign('msg_create_note',__("The site alias may only contain letters, numbers and underscores."));
00164     $page->assign('msg_submit',__("Submit"));
00165     $page->assign('msg_no_barrels', __("no barrels available"));
00166     $page->assign('msg_vhost',__("vhost (see note)"));
00167     $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."));
00168     $page->assign('msg_flags',__("flags"));
00169     
00170         // if requested, assign the content to be displayed
00171     if (!empty($outputvar)) {
00172       $page->assign($outputvar, $page->fetch('barrel-editor.tpl'));
00173     }
00174   }
00175 }
00176 ?>

Generated on Fri Jan 11 01:20:08 2008 for Diogenes by  doxygen 1.5.1