| 1 |
<?php
|
| 2 |
|
| 3 |
// PROVISIONATOR SITE NODE FUNCTIONS
|
| 4 |
|
| 5 |
include_once('provisionator_helper.inc');
|
| 6 |
|
| 7 |
/**
|
| 8 |
* Implementation of hook_access().
|
| 9 |
*/
|
| 10 |
function provisionatorsite_access($op, $node) {
|
| 11 |
global $user;
|
| 12 |
|
| 13 |
if ($op == 'create') {
|
| 14 |
return user_access('deploy new site');
|
| 15 |
}
|
| 16 |
|
| 17 |
if ($op == 'update') {
|
| 18 |
if ((user_access('edit own deployed sites') && ($user->uid == $node->uid)) || (user_access('administer deployed sites'))) {
|
| 19 |
return TRUE;
|
| 20 |
}
|
| 21 |
}
|
| 22 |
|
| 23 |
if ($op == 'delete') {
|
| 24 |
if ((user_access('delete own deployed sites') && ($user->uid == $node->uid)) || (user_access('administer deployed sites'))) {
|
| 25 |
return TRUE;
|
| 26 |
}
|
| 27 |
}
|
| 28 |
}
|
| 29 |
|
| 30 |
|
| 31 |
/**
|
| 32 |
* Implementation of hook_delete().
|
| 33 |
*/
|
| 34 |
function provisionatorsite_delete(&$node) {
|
| 35 |
// TODO: Enter database deletion query here, for example:
|
| 36 |
// db_query('DELETE FROM {node_example} WHERE nid = %d', $node->nid);
|
| 37 |
db_query("DELETE FROM {provisionatorsite} WHERE nid = %d", $node->nid);
|
| 38 |
}
|
| 39 |
|
| 40 |
|
| 41 |
/**
|
| 42 |
* Implementation of hook_form().
|
| 43 |
*/
|
| 44 |
function provisionatorsite_form(&$node, &$param) {
|
| 45 |
$form['title'] = array(
|
| 46 |
'#type' => 'textfield',
|
| 47 |
'#title' => t('Title'),
|
| 48 |
'#required' => TRUE,
|
| 49 |
'#default_value' => $node->title,
|
| 50 |
'#weight' => -5
|
| 51 |
);
|
| 52 |
|
| 53 |
$form['body_filter']['body'] = array(
|
| 54 |
'#type' => 'textarea',
|
| 55 |
'#title' => t('Description'),
|
| 56 |
'#default_value' => $node->body,
|
| 57 |
'#required' => TRUE
|
| 58 |
);
|
| 59 |
|
| 60 |
$form['body_filter']['filter'] = filter_form($node->format);
|
| 61 |
|
| 62 |
$form['shortname'] = array(
|
| 63 |
'#type' => 'textfield',
|
| 64 |
'#title' => t('Shortname'),
|
| 65 |
'#required' => TRUE,
|
| 66 |
'#default_value' => $node->shortname,
|
| 67 |
'#description' => t('The short name for the site, used in the url (eg. www.server.com/shortname) and in the database name.')
|
| 68 |
);
|
| 69 |
|
| 70 |
$form['status'] = array(
|
| 71 |
'#type' => 'select',
|
| 72 |
'#title' => t('Status'),
|
| 73 |
'#options' => getStatusArray(),
|
| 74 |
'#default_value' => $node->sitestatus,
|
| 75 |
'#description' => t('Status of the site - select an option.')
|
| 76 |
);
|
| 77 |
|
| 78 |
$form['fullurl'] = array(
|
| 79 |
'#type' => 'textfield',
|
| 80 |
'#title' => t('Full URL of site'),
|
| 81 |
'#default_value' => $node->fullurl,
|
| 82 |
'#required' => FALSE,
|
| 83 |
'#description' => t('Full, qualified URL of the site. If you open the site in a browser, this is the address. Leave empty to use defaults from Client and shortname.')
|
| 84 |
);
|
| 85 |
|
| 86 |
$form['profile'] = array(
|
| 87 |
'#type' => 'select',
|
| 88 |
'#title' => t('Site Profile'),
|
| 89 |
'#default_value' => $node->profile,
|
| 90 |
'#required' => TRUE,
|
| 91 |
'#description' => t('Which database template should be used when setting up this site?'),
|
| 92 |
'#options' => provisionator_get_profiles(),
|
| 93 |
);
|
| 94 |
|
| 95 |
$form['client'] = array(
|
| 96 |
'#type' => 'select',
|
| 97 |
'#title' => t('Client'),
|
| 98 |
'#default_value' => $node->clientid,
|
| 99 |
'#options' => getClientListOptions(),
|
| 100 |
'#description' => t('Who is the site for? This will be associated with the Provisionator Client node, and will cause particular settings to be inherited by this site (eg. URL prefix, database prefix, etc...)')
|
| 101 |
);
|
| 102 |
|
| 103 |
|
| 104 |
// TODO: Enter additional form elements
|
| 105 |
|
| 106 |
return $form;
|
| 107 |
}
|
| 108 |
|
| 109 |
function getStatusArray() {
|
| 110 |
$statusarray = array(
|
| 111 |
t('Active'),
|
| 112 |
t('Static'),
|
| 113 |
t('Abandoned'),
|
| 114 |
t('Freeze Dried'),
|
| 115 |
t('Disabled')
|
| 116 |
);
|
| 117 |
return $statusarray;
|
| 118 |
}
|
| 119 |
|
| 120 |
// this function should query all nodes of type provisionatorclient and return them in alpha order
|
| 121 |
function getClientListOptions() {
|
| 122 |
$clientsql = "SELECT title, nid FROM {node} WHERE type = 'provisionatorclient'";
|
| 123 |
$result = db_query($clientsql);
|
| 124 |
$options = array();
|
| 125 |
|
| 126 |
while ($anode = db_fetch_object($result)) {
|
| 127 |
$clientid = $anode->nid;
|
| 128 |
$options[$clientid] = $anode->title;
|
| 129 |
}
|
| 130 |
return $options;
|
| 131 |
}
|
| 132 |
|
| 133 |
/**
|
| 134 |
* Implementation of hook_insert().
|
| 135 |
*/
|
| 136 |
function provisionatorsite_insert($node) {
|
| 137 |
|
| 138 |
// check for fullurl. if not provided, generate it.
|
| 139 |
// settings pulled from the provisionatorclient node
|
| 140 |
// try to load the client node for the given clientid
|
| 141 |
$client = db_fetch_object(db_query("SELECT dbprefix, symlinkpath, domainprefix from {provisionatorclient} where nid = %d", $node->client));
|
| 142 |
|
| 143 |
// check to see if a fullurl has (not) been provided. In that case, generate one from the client and site data.
|
| 144 |
if (($node->fullurl == NULL) || ($node->fullurl == '')) {
|
| 145 |
$node->fullurl = 'http://'.$client->domainprefix . '/' . $node->shortname;
|
| 146 |
}
|
| 147 |
|
| 148 |
// first, try to provision the site
|
| 149 |
$deployresult = provisionator_deploy_site( $node );
|
| 150 |
|
| 151 |
// successful? insert that sucker.
|
| 152 |
if ($deployresult == TRUE) {
|
| 153 |
db_query("INSERT INTO {provisionatorsite} (nid, shortname, sitestatus, fullurl, profile, clientid) VALUES (%d, '%s', %d, '%s', '%s', %d)", $node->nid, $node->shortname, $node->sitestatus, $node->fullurl, $node->profile, $node->client);
|
| 154 |
} else {
|
| 155 |
drupal_set_message(t('Error deploying the site. Record not saved.'));
|
| 156 |
}
|
| 157 |
}
|
| 158 |
|
| 159 |
|
| 160 |
/**
|
| 161 |
* Implementation of hook_load().
|
| 162 |
*/
|
| 163 |
function provisionatorsite_load($node) {
|
| 164 |
// TODO: Obtain and return additional fields added to the node type, for example:
|
| 165 |
// $additions = db_fetch_object(db_query('SELECT color, quantity FROM {node_example} WHERE vid = %d', $node->vid));
|
| 166 |
// return $additions;
|
| 167 |
$additions = db_fetch_object(db_query('SELECT shortname, sitestatus, fullurl, profile, clientid FROM {provisionatorsite} WHERE nid = %d', $node->nid));
|
| 168 |
|
| 169 |
return $additions;
|
| 170 |
}
|
| 171 |
|
| 172 |
/**
|
| 173 |
* Implementation of hook_prepare().
|
| 174 |
*/
|
| 175 |
function provisionatorsite_prepare(&$node) {
|
| 176 |
|
| 177 |
}
|
| 178 |
|
| 179 |
/**
|
| 180 |
* Implementation of hook_submit().
|
| 181 |
*/
|
| 182 |
function provisionatorsite_submit(&$node) {
|
| 183 |
|
| 184 |
}
|
| 185 |
|
| 186 |
/**
|
| 187 |
* Implementation of hook_update().
|
| 188 |
*/
|
| 189 |
function provisionatorsite_update($node) {
|
| 190 |
if ($node->revision) {
|
| 191 |
provisionatorsite_insert($node);
|
| 192 |
}
|
| 193 |
else {
|
| 194 |
// TODO: Enter database update query here, for example:
|
| 195 |
// db_query("UPDATE {node_example} SET color = '%s', quantity = %d WHERE vid = %d", $node->color, $node->quantity, $node->vid);
|
| 196 |
db_query("UPDATE {provisionatorsite} SET shortname = '%s', sitestatus = %d, fullurl = '%s', clientid = %d WHERE nid = %d", $node->shortname, $node->sitestatus, $node->fullurl, $node->client, $node->nid);
|
| 197 |
drupal_set_message('status: ' . $node->sitestatus);
|
| 198 |
}
|
| 199 |
}
|
| 200 |
|
| 201 |
/**
|
| 202 |
* Implementation of hook_validate().
|
| 203 |
*/
|
| 204 |
function provisionatorsite_validate(&$node) {
|
| 205 |
// TODO: Enter form validation code here
|
| 206 |
}
|
| 207 |
|
| 208 |
/**
|
| 209 |
* Implementation of hook_view().
|
| 210 |
*/
|
| 211 |
function provisionatorsite_view(&$node, $teaser = FALSE, $page = FALSE) {
|
| 212 |
// TODO: Insert additional code (call to theme functions, etc.) to execute when viewing a node, for example:
|
| 213 |
// $node = node_prepare($node, $teaser);
|
| 214 |
// $order_info = theme('node_example_order_info', $node);
|
| 215 |
// $node->body .= $order_info;
|
| 216 |
// $node->teaser .= $order_info;
|
| 217 |
|
| 218 |
$node = node_prepare( $node, $teaser );
|
| 219 |
|
| 220 |
// try to load the client node for the given clientid
|
| 221 |
$client_result = db_fetch_object(db_query("SELECT title from {node} where nid = %d", $node->clientid));
|
| 222 |
|
| 223 |
$statusarray = getStatusArray();
|
| 224 |
|
| 225 |
$site_info = '';
|
| 226 |
$site_info .= t('<br />Site Shortname: ').$node->shortname;
|
| 227 |
$site_info .= t('<br />Status: ').$statusarray[$node->sitestatus];
|
| 228 |
$site_info .= t('<br />Full URL: ').$node->fullurl;
|
| 229 |
$site_info .= t('<br />Client: '.$client_result->title);
|
| 230 |
|
| 231 |
$node->body .= $site_info;
|
| 232 |
$node->teaser .= $site_info;
|
| 233 |
}
|
| 234 |
|
| 235 |
|
| 236 |
?>
|