2007-08-18 13:38:11 +02:00
|
|
|
<?php
|
2008-11-24 04:22:01 +01:00
|
|
|
/**
|
|
|
|
* Admin interface to manage and create {@link Subsite} instances.
|
|
|
|
*
|
|
|
|
* @package subsites
|
|
|
|
*/
|
2007-08-18 13:38:11 +02:00
|
|
|
class SubsiteAdmin extends GenericDataAdmin {
|
|
|
|
|
|
|
|
static $tree_class = "Subsite";
|
|
|
|
static $subitem_class = "Subsite";
|
|
|
|
static $data_type = 'Subsite';
|
|
|
|
|
2008-11-02 23:23:01 +01:00
|
|
|
static $url_segment = 'subsites';
|
|
|
|
|
|
|
|
static $url_rule = '/$Action/$ID/$OtherID';
|
|
|
|
|
|
|
|
static $menu_title = 'Subsites';
|
|
|
|
|
2007-08-18 13:38:11 +02:00
|
|
|
function performSearch() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSearchFields() {
|
|
|
|
return singleton('Subsite')->adminSearchFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLink() {
|
2007-08-21 00:37:43 +02:00
|
|
|
return 'admin/subsites/';
|
2007-08-18 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function Link() {
|
|
|
|
return $this->getLink();
|
|
|
|
}
|
|
|
|
|
2007-08-21 00:37:43 +02:00
|
|
|
function Results($data = null) {
|
|
|
|
if(!$data) $data = $this->requestParams;
|
|
|
|
|
2009-11-02 04:00:18 +01:00
|
|
|
if(defined('DB::USE_ANSI_SQL'))
|
|
|
|
$q="\"";
|
|
|
|
else $q='`';
|
|
|
|
|
2007-08-18 13:38:11 +02:00
|
|
|
$where = '';
|
|
|
|
if(isset($data['Name']) && $data['Name']) {
|
|
|
|
$SQL_name = Convert::raw2sql($data['Name']);
|
2009-11-02 04:00:18 +01:00
|
|
|
$where = "{$q}Title{$q} LIKE '%$SQL_name%'";
|
2008-02-26 04:14:27 +01:00
|
|
|
} else {
|
2009-11-02 04:00:18 +01:00
|
|
|
$where = "{$q}Title{$q} != ''";
|
2007-08-18 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2009-07-14 03:41:51 +02:00
|
|
|
$intranets = null;
|
2009-11-02 04:00:18 +01:00
|
|
|
$intranets = DataObject::get('Subsite_Template', $where, "{$q}Title{$q}");
|
|
|
|
$subsites = DataObject::get('Subsite', $where, "{$q}Title{$q}");
|
2009-07-14 03:41:51 +02:00
|
|
|
|
|
|
|
if($intranets) {
|
|
|
|
$intranets->merge($subsites);
|
|
|
|
} else {
|
|
|
|
$intranets = $subsites;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$intranets) return null;
|
|
|
|
|
|
|
|
$intranets->removeDuplicates();
|
|
|
|
|
2007-08-18 13:38:11 +02:00
|
|
|
$html = "<table class=\"ResultTable\"><thead><tr><th>Name</th><th>Domain</th></tr></thead><tbody>";
|
|
|
|
|
|
|
|
$numIntranets = 0;
|
|
|
|
foreach($intranets as $intranet) {
|
|
|
|
$numIntranets++;
|
|
|
|
$evenOdd = ($numIntranets % 2) ? 'odd':'even';
|
2007-08-29 00:29:44 +02:00
|
|
|
$prefix = ($intranet instanceof Subsite_Template) ? " * " : "";
|
|
|
|
$html .= "<tr class=\"$evenOdd\"><td><a class=\"show\" href=\"admin/subsites/show/{$intranet->ID}\">$prefix{$intranet->Title}</a></td><td><a class=\"show\" href=\"admin/subsites/show/{$intranet->ID}\">{$intranet->Subdomain}.{$intranet->Domain}</a></td></tr>";
|
2007-08-18 13:38:11 +02:00
|
|
|
}
|
|
|
|
$html .= "</tbody></table>";
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
2007-08-21 03:38:20 +02:00
|
|
|
/**
|
|
|
|
* Returns the form for adding subsites.
|
|
|
|
* @returns Form A nerw form object
|
|
|
|
*/
|
2007-08-18 13:38:11 +02:00
|
|
|
function AddSubsiteForm() {
|
|
|
|
$templates = $this->getIntranetTemplates();
|
|
|
|
|
2008-11-20 00:25:43 +01:00
|
|
|
$templateArray = array('' => "(No template)");
|
2007-08-18 13:38:11 +02:00
|
|
|
if($templates) {
|
2008-11-20 00:25:43 +01:00
|
|
|
$templateArray = $templateArray + $templates->map('ID', 'Title');
|
2007-08-18 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 03:38:20 +02:00
|
|
|
return new Form($this, 'AddSubsiteForm', new FieldSet(
|
2007-08-18 13:38:11 +02:00
|
|
|
new TextField('Name', 'Name:'),
|
|
|
|
new TextField('Subdomain', 'Subdomain:'),
|
2007-08-29 00:29:44 +02:00
|
|
|
new DropdownField('Type', 'Type', array(
|
|
|
|
'subsite' => 'New site',
|
|
|
|
'template' => 'New template',
|
|
|
|
)),
|
2009-05-04 07:03:44 +02:00
|
|
|
new DropdownField('TemplateID', 'Copy structure from:', $templateArray)//,
|
2007-12-10 03:32:24 +01:00
|
|
|
/*new TextField('AdminName', 'Admin name:'),
|
|
|
|
new EmailField('AdminEmail', 'Admin email:')*/
|
2007-08-18 13:38:11 +02:00
|
|
|
),
|
|
|
|
new FieldSet(
|
|
|
|
new FormAction('addintranet', 'Add')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIntranetTemplates() {
|
2009-11-02 04:00:18 +01:00
|
|
|
if(defined('DB::USE_ANSI_SQL'))
|
|
|
|
$q="\"";
|
|
|
|
else $q='`';
|
|
|
|
|
|
|
|
return DataObject::get('Subsite_Template', '', "{$q}Title{$q}");
|
2007-08-18 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addintranet($data, $form) {
|
2009-02-24 23:36:09 +01:00
|
|
|
if($data['Name'] && ($data['Subdomain'] || $data['Type'] == 'template')) {
|
2008-11-20 00:25:43 +01:00
|
|
|
if(isset($data['TemplateID']) && $data['TemplateID']) {
|
|
|
|
$template = DataObject::get_by_id('Subsite_Template', $data['TemplateID']);
|
|
|
|
} else {
|
|
|
|
$template = null;
|
|
|
|
}
|
2007-08-18 13:38:11 +02:00
|
|
|
|
2007-11-27 02:07:54 +01:00
|
|
|
// Create intranet from existing template
|
|
|
|
switch($data['Type']) {
|
|
|
|
case 'template':
|
2008-11-20 00:25:43 +01:00
|
|
|
if($template) $intranet = $template->duplicate();
|
|
|
|
else $intranet = new Subsite_Template();
|
|
|
|
|
2007-11-27 02:07:54 +01:00
|
|
|
$intranet->Title = $data['Name'];
|
|
|
|
$intranet->write();
|
|
|
|
break;
|
2007-08-29 00:29:44 +02:00
|
|
|
|
2007-11-27 02:07:54 +01:00
|
|
|
case 'subsite':
|
2008-11-20 00:25:43 +01:00
|
|
|
default:
|
|
|
|
if($template) $intranet = $template->createInstance($data['Name'], $data['Subdomain']);
|
|
|
|
else {
|
|
|
|
$intranet = new Subsite();
|
|
|
|
$intranet->Title = $data['Name'];
|
|
|
|
$intranet->Subdomain = $data['Subdomain'];
|
|
|
|
$intranet->write();
|
|
|
|
}
|
2007-11-27 02:07:54 +01:00
|
|
|
break;
|
|
|
|
}
|
2007-08-18 13:38:11 +02:00
|
|
|
|
2007-11-27 02:07:54 +01:00
|
|
|
Director::redirect('admin/subsites/show/' . $intranet->ID);
|
|
|
|
} else {
|
2009-02-24 23:36:09 +01:00
|
|
|
if($data['Type'] == 'template') echo "You must provide a name for your new template.";
|
|
|
|
else echo "You must provide a name and subdomain for your new site.";
|
2007-11-27 02:07:54 +01:00
|
|
|
}
|
2007-08-18 13:38:11 +02:00
|
|
|
}
|
2007-10-11 05:05:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use this as an action handler for custom CMS buttons.
|
|
|
|
*/
|
|
|
|
function callPageMethod2($data, $form) {
|
|
|
|
return $this->callPageMethod($data, $form);
|
|
|
|
}
|
2007-08-18 13:38:11 +02:00
|
|
|
}
|
|
|
|
?>
|