Commit ce65c400 authored by anarcat's avatar anarcat Committed by anarcat

Merge commit 'hostmaster/master'

parents 2e0e3c0f f206040e
File mode changed from 100755 to 100644
......@@ -148,14 +148,13 @@ function hosting_client_form(&$node) {
);
if ($node->nid) {
// this should probably be factored out in a common function
$q = db_query("SELECT u.uid, u.name FROM {hosting_client_user} h INNER JOIN {users} u ON u.uid = h.user WHERE h.client = %d", $node->nid);
while ($result = db_fetch_array($q)) {
$form['user_edit']['name'][$result['uid']] = array('#type' => 'markup', '#value' => l($result['name'], 'user/' . $result['uid']));
$users[$result['uid']] = '';
$users = hosting_client_users($node);
foreach ($users as $uid => $uname) {
$form['user_edit']['name'][$uid] = array('#type' => 'markup', '#value' => l($uname, 'user/' . $uid));
$user_list[$uid] = '';
}
if (user_access('edit client users')) {
$form['user_edit']['users'] = array('#type' => 'checkboxes', '#options' => $users);
$form['user_edit']['users'] = array('#type' => 'checkboxes', '#options' => $user_list);
}
$form['user_edit']['header'] = array('#type' => 'value', '#value' => array(array('data' => t('Allowed users')), array('data' => t('Remove'))));
if (user_access('edit client users')) {
......@@ -346,12 +345,59 @@ function hosting_client_delete($node) {
/**
* Implementation of hook_load().
*
* @param node
* Node object
*/
function hosting_client_load($node) {
$additions = db_fetch_object(db_query('SELECT name as client_name, organization, email FROM {hosting_client} WHERE vid = %d', $node->vid));
return $additions;
}
/**
* Implementation of hook_load().
*
* @param arg
* Node's numeric nid
*/
function hosting_client_node_load($arg) {
if (!is_numeric($arg)) {
return FALSE;
}
if ($node = node_load($arg)) {
if ($node->type == 'client') {
return $node;
}
}
return FALSE;
}
/**
* Return a list of users for a given client.
*
* @param node
* Client node (as nid or node object)
* @return
* Array of user names indexed by uid
*
*/
function hosting_client_users($node) {
if (is_object($node)) {
$node = $node->nid;
}
elseif (!is_numeric($node)) {
return array();
}
$users = array();
$q = db_query("SELECT u.uid, u.name FROM {hosting_client_user} h INNER JOIN {users} u ON u.uid = h.user WHERE h.client = %d", $node);
while ($result = db_fetch_array($q)) {
$users[$result['uid']] = $result['name'];
}
return $users;
}
/**
* Implementation of hook_view().
*/
......@@ -383,30 +429,29 @@ function hosting_client_view($node, $teaser = FALSE, $page = FALSE) {
if ($page) {
$node->content['sites_view'] = array(
'#type' => 'item',
'#value' => hosting_site_list("client", $node->nid),
'#value' => hosting_site_list("client", $node->nid),
'#prefix' => '<div id="hosting-site-list">',
'#suffix' => '</div>',
'#suffix' => '</div>',
'#weight' => 10
);
// this should probably be factored out in a common function
$q = db_query("SELECT u.uid, u.name FROM {hosting_client_user} h INNER JOIN {users} u ON u.uid = h.user WHERE h.client = %d", $node->nid);
while ($result = db_fetch_array($q)) {
if (user_access('view users') || ($result['uid'] == $GLOBALS['user']->uid)) {
$rows[] = array(l($result['name'], 'user/' . $result['uid']));
$users = hosting_client_users($node);
foreach ($users as $uid => $uname) {
if (user_access('access user profiles') || ($uid == $GLOBALS['user']->uid)) {
$rows[] = array(l($uname, 'user/' . $uid));
}
else {
$rows[] = array($result['name']);
$rows[] = array($uname);
}
}
$header = array(t('Allowed users'));
$node->content['users_view'] = array(
'#type' => 'item',
'#value' => theme('table', $header, $rows),
'#class' => 'client',
'#prefix' => '<div id="hosting-site-list">',
'#suffix' => '</div>',
'#suffix' => '</div>',
'#weight' => 11
);
}
......
......@@ -17,12 +17,11 @@ function hosting_migrate_menu() {
$items['hosting/migrate/compare'] = array(
'title' => 'Compare packages',
'page callback' => 'hosting_migrate_comparison',
'access arguments' => array('create migrate task'),
'type' => MENU_CALLBACK
);
/*
$items['node/%hosting_task_platform/task_migrate'] = array(
$items['node/%hosting_platform_node/task_migrate'] = array(
'title' => t('Migrate'),
'description' => t('Migrate sites to a new platform'),
'page callback' => 'drupal_get_form',
......
......@@ -306,6 +306,9 @@ function hosting_platform_validate($node, &$form) {
/**
* Implementation of hook_load().
*
* @param node
* Node object
*/
function hosting_platform_load($node) {
$additions = db_fetch_object(db_query('SELECT publish_path, verified, web_server, status AS platform_status FROM {hosting_platform} WHERE vid = %d', $node->vid));
......@@ -314,6 +317,24 @@ function hosting_platform_load($node) {
return $additions;
}
/**
* Implementation of hook_load().
*
* @param arg
* Node's numeric nid
*/
function hosting_platform_node_load($arg) {
if (!is_numeric($arg)) {
return FALSE;
}
if ($node = node_load($arg)) {
if ($node->type == 'platform') {
return $node;
}
}
return FALSE;
}
/**
* Implementation of hook_view().
*/
......
......@@ -108,19 +108,28 @@ function hosting_services_new_object($name, $type, $node, $values = null) {
$services = hosting_server_services();
$class = $services[$name]['types'][$type];
if (!$class) {
drupal_set_message(t("Can't create service object for service !name", array("!name" => $name)), "error");
return;
}
return new $class($node, $values);
}
function hosting_services_add(&$node, $name, $type, $values = array()) {
$values['available'] = (isset($values['available'])) ? $values['available'] : 1;
$node->services[$name] = hosting_services_new_object($name, $type, $node, $values);
if ($service_object = hosting_services_new_object($name, $node, $values)) {
$node->services[$name] = $service_object;
}
}
function hosting_server_init_services(&$node) {
$result = db_query("SELECT service, type FROM {hosting_service} WHERE vid=%d AND available=1", $node->vid);
while ($record = db_fetch_object($result)) {
$node->services[$record->service] = hosting_services_new_object($record->service, $record->type, $node);
$name = $record->service;
if ($service_object = hosting_services_new_object($name, $record->type, $node)) {
$node->services[$name] = $service_object;
}
}
return $node;
......@@ -131,8 +140,10 @@ function hosting_server_services_from_post(&$node) {
foreach (hosting_server_services() as $name => $data) {
if (is_array($node->services[$name])) {
if ($node->services[$name]['type'] !== 'null') {
$node->services[$name] = hosting_services_new_object($name, $node->services[$name]['type'], $node, $node->services[$name][$node->services[$name]['type']]);
$node->services[$name]->available = TRUE;
if ($service_object = hosting_services_new_object($name, $node->services[$name]['type'], $node, $node->services[$name][$node->services[$name]['type']])) {
$node->services[$name] = hosting_services_new_object($name, $node->services[$name]['type'], $node, $node->services[$name][$node->services[$name]['type']]);
$node->services[$name]->available = TRUE;
}
}
else {
unset($node->services[$name]);
......@@ -308,6 +319,24 @@ function hosting_server_load($node) {
return $additions;
}
/**
* Menu callback; loads a hosting_task_server node
*
* @arg $arg a numeric nid
*/
function hosting_server_node_load($arg) {
if (!is_numeric($arg)) {
return FALSE;
}
if ($node = node_load($arg)) {
if ($node->type === 'server') {
return $node;
}
}
return FALSE;
}
/**
* Implementation of hook_view().
*/
......
......@@ -528,12 +528,33 @@ function hosting_site_update(&$node) {
/**
* Implementation of hook_load().
*
* @param node
* Node object
*/
function hosting_site_load($node) {
$additions = db_fetch_object(db_query('SELECT client, db_server, platform, profile, language as site_language, last_cron, status AS site_status, verified, port, `ssl`, ssl_redirect FROM {hosting_site} WHERE vid = %d', $node->vid));
return $additions;
}
/**
* Implementation of hook_load().
*
* @param arg
* Node's numeric nid
*/
function hosting_site_node_load($arg) {
if (!is_numeric($arg)) {
return FALSE;
}
if ($node = node_load($arg)) {
if ($node->type == 'site') {
return $node;
}
}
return FALSE;
}
/**
* Implementation of hook_nodeapi_delete_revision().
*/
......@@ -895,7 +916,7 @@ function hosting_site_menu() {
'access arguments' => array('access content'),
);
$items['node/%hosting_task_site/goto_site'] = array(
$items['node/%hosting_site_node/goto_site'] = array(
'page callback' => 'hosting_site_goto',
'page arguments' => array(1),
'access callback' => 'node_access',
......
......@@ -11,7 +11,7 @@ function hosting_task_menu() {
foreach (array('site', 'platform', 'server') as $type) {
foreach (hosting_available_tasks($type) as $task => $info) {
if (empty($info['hidden'])) {
$path = sprintf("node/%%hosting_task_%s/%s_%s", $type, $type, $task);
$path = sprintf("node/%%hosting_%s_node/%s_%s", $type, $type, $task);
$items[$path] = array(
'title' => $info['title'],
'description' => $info['description'],
......@@ -126,42 +126,6 @@ function hosting_task_menu_access($node, $task) {
return FALSE;
}
function hosting_task_site_load($arg) {
if (!is_numeric($arg)) {
return FALSE;
}
if ($node = node_load($arg)) {
if ($node->type == 'site') {
return $node;
}
}
return FALSE;
}
function hosting_task_platform_load($arg) {
if (!is_numeric($arg)) {
return FALSE;
}
if ($node = node_load($arg)) {
if ($node->type == 'platform') {
return $node;
}
}
return FALSE;
}
function hosting_task_server_load($arg) {
if (!is_numeric($arg)) {
return FALSE;
}
if ($node = node_load($arg)) {
if ($node->type === 'server') {
return $node;
}
}
return FALSE;
}
/**
* Implementation of hook_node_info()
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment