| 1 |
<?php
|
| 2 |
// $Id: lmo.module,v 1.21 2008/08/25 18:13:43 martinsfromb Exp $
|
| 3 |
|
| 4 |
include('lmo.common.inc');
|
| 5 |
|
| 6 |
function lmo_menu() {
|
| 7 |
|
| 8 |
$items = array();
|
| 9 |
|
| 10 |
$items['admin/settings/lmo'] = array(
|
| 11 |
'title' => t('LMO settings'),
|
| 12 |
'description' => t('Set the preferences to access LMO.'),
|
| 13 |
'page callback' => 'drupal_get_form',
|
| 14 |
'page arguments' => array('lmo_settings_form'),
|
| 15 |
'access arguments' => array('administer site configuration'),
|
| 16 |
'type' => MENU_NORMAL_ITEM,
|
| 17 |
);
|
| 18 |
|
| 19 |
|
| 20 |
$items['lmo'] = array(
|
| 21 |
'title' => t('League Manager Online'),
|
| 22 |
'page callback' => 'lmo_page',
|
| 23 |
'access arguments' => array('access content'),
|
| 24 |
'type' => MENU_CALLBACK,
|
| 25 |
'weight' => 1,
|
| 26 |
);
|
| 27 |
|
| 28 |
$items['admin/content/lmo'] = array(
|
| 29 |
'title' => t('LMO administration'),
|
| 30 |
'description' => t('Administer your leagues and standings with LMO.'),
|
| 31 |
'access arguments' => array('administer lmo'),
|
| 32 |
'page callback' => 'lmo_page_backend',
|
| 33 |
);
|
| 34 |
|
| 35 |
$items['admin/content/lmo/backend'] = array(
|
| 36 |
'title' => t('LMO Admin Mode'),
|
| 37 |
'access arguments' => array('administer lmo'),
|
| 38 |
'page callback' => 'lmo_page_backend',
|
| 39 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 40 |
'weight' => 0,
|
| 41 |
);
|
| 42 |
|
| 43 |
$items['admin/content/lmo/drupal'] = array(
|
| 44 |
'title' => t('LMO Drupal Integration'),
|
| 45 |
'access arguments' => array('administer lmo'),
|
| 46 |
'type' => MENU_LOCAL_TASK,
|
| 47 |
'page callback' => 'drupal_get_form',
|
| 48 |
'page arguments' => array('lmo_admin_integration_form'),
|
| 49 |
'weight' => 1,
|
| 50 |
);
|
| 51 |
|
| 52 |
$items['admin/content/lmo/drupal/content'] = array(
|
| 53 |
'title' => t('Content Integration Options'),
|
| 54 |
'access arguments' => array('administer lmo'),
|
| 55 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 56 |
'page arguments' => array('lmo_admin_integration_form'),
|
| 57 |
'weight' => 0,
|
| 58 |
);
|
| 59 |
|
| 60 |
$items['admin/content/lmo/drupal/blocks'] = array(
|
| 61 |
'title' => t('Blocks'),
|
| 62 |
'access arguments' => array('administer lmo'),
|
| 63 |
'type' => MENU_LOCAL_TASK,
|
| 64 |
'page arguments' => array('lmo_admin_integration_form', 'blocks'),
|
| 65 |
'weight' => 1,
|
| 66 |
);
|
| 67 |
|
| 68 |
$items['admin/content/lmo/drupal/blocks/add'] = array(
|
| 69 |
'title' => t('Add a block with content from LMO'),
|
| 70 |
'access arguments' => array('administer lmo'),
|
| 71 |
'type' => MENU_CALLBACK,
|
| 72 |
'page arguments' => array('lmo_admin_integration_form', 'blocksadd'),
|
| 73 |
'weight' => 1,
|
| 74 |
);
|
| 75 |
|
| 76 |
$items['admin/content/lmo/drupal/blocks/delete'] = array(
|
| 77 |
'title' => t('Shure to delete the block?'),
|
| 78 |
'access arguments' => array('administer lmo'),
|
| 79 |
'type' => MENU_CALLBACK,
|
| 80 |
'page arguments' => array('lmo_admin_integration_form', 'blocksdelete', 6),
|
| 81 |
'weight' => 1,
|
| 82 |
);
|
| 83 |
|
| 84 |
$items['admin/content/lmo/drupal/blocks/conf'] = array(
|
| 85 |
'title' => t('Configure lmo-block'),
|
| 86 |
'access arguments' => array('administer lmo'),
|
| 87 |
'type' => MENU_CALLBACK,
|
| 88 |
'page arguments' => array('lmo_admin_integration_form', 'blocksconf', 6),
|
| 89 |
'weight' => 1,
|
| 90 |
);
|
| 91 |
|
| 92 |
return $items;
|
| 93 |
}
|
| 94 |
|
| 95 |
function lmo_admin_integration_form(&$form_state, $task = 'options', $id = 0) {
|
| 96 |
$lmo_path= variable_get('lmo_local_path','');
|
| 97 |
$form=array();
|
| 98 |
switch ($task)
|
| 99 |
{
|
| 100 |
case 'blocks':
|
| 101 |
$blockarray = lmo_getblocksdata();
|
| 102 |
$form['text1'] = array(
|
| 103 |
'#type' => 'markup',
|
| 104 |
'#value' => t('Here is a list of the blocks bringing up lmo-content to your drupal site.<br />'.l('Create new needed blocks here ...', 'admin/content/lmo/drupal/blocks/add')),
|
| 105 |
);
|
| 106 |
$header = array (t('Title'),t('Type'), t('Status'), t('Actions'));
|
| 107 |
$rows = array();
|
| 108 |
foreach ($blockarray as $block)
|
| 109 |
{
|
| 110 |
$status = lmo_check_blockstatus ($block);
|
| 111 |
if ($status['ok'] == true) {
|
| 112 |
$statusmessage = t('o.k.');
|
| 113 |
} else $statusmessage = '<span class="error">'.t('broken').'</span>';
|
| 114 |
/*$statusmessage .= ' | ';
|
| 115 |
if ($status['visible'] == true) {
|
| 116 |
$statusmessage .= t('visible');
|
| 117 |
} else $statusmessage .= t('not visible');*/
|
| 118 |
$actions = '<ul>';
|
| 119 |
$actions .= '<li>'.l('Configure','admin/content/lmo/drupal/blocks/conf/'.$block['delta']).'</li>';
|
| 120 |
$actions .= '<li>'.l('Delete','admin/content/lmo/drupal/blocks/delete/'.$block['delta']).'</li>';
|
| 121 |
$actions .= '</ul>';
|
| 122 |
$rows[] = array(
|
| 123 |
$block['title'],
|
| 124 |
$block['type'],
|
| 125 |
$statusmessage,
|
| 126 |
$actions,
|
| 127 |
);
|
| 128 |
}
|
| 129 |
$form['table'] = array(
|
| 130 |
'#type' => 'markup',
|
| 131 |
'#value' => theme('table',$header, $rows),
|
| 132 |
);
|
| 133 |
break;
|
| 134 |
case 'blocksdelete':
|
| 135 |
$form['foo'] = array(
|
| 136 |
'#type' => 'markup',
|
| 137 |
'#title' => t('test'),
|
| 138 |
'#description' => t('test description'),
|
| 139 |
'#value' => t('Do you really want to delete the block with id').' '.$id.'?',
|
| 140 |
);
|
| 141 |
$form['task'] = array('#type' => 'hidden', '#value' => 'blocksdelete');
|
| 142 |
$form['blockid'] = array('#type' => 'hidden', '#value' => $id);
|
| 143 |
$form['foo2'] = array(
|
| 144 |
'#type' => 'markup',
|
| 145 |
'#value' => '<br />',
|
| 146 |
);
|
| 147 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Delete'), '#weight' => 51);
|
| 148 |
$form['cancel'] = array('#type' => 'button', '#value' => t('Cancel'), '#weight' => 50);
|
| 149 |
break;
|
| 150 |
case 'blocksadd':
|
| 151 |
$form['foo'] = array(
|
| 152 |
'#type' => 'markup',
|
| 153 |
'#value' => t('Here you can add a block to present content from the LMO to your website.'),
|
| 154 |
);
|
| 155 |
$form['title'] = array(
|
| 156 |
'#type' => 'textfield',
|
| 157 |
'#title' => t('Title'),
|
| 158 |
'#description' => t('You can give your block any title you want'),
|
| 159 |
);
|
| 160 |
$form['blocktype'] = array(
|
| 161 |
'#type' => 'radios',
|
| 162 |
'#title' => t('Block type'),
|
| 163 |
'#description' => t('Select what type of LMO-block you want to create!'),
|
| 164 |
'#options' => array('Rank list<br/><em>Create a block containing the standings of a specific leaque.</em>','Chart<br /><em>Create a block containing chart for a specific team.</em>'),
|
| 165 |
);
|
| 166 |
$form['task'] = array('#type' => 'hidden', '#value' => 'blocksadd');
|
| 167 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Create block'));
|
| 168 |
break;
|
| 169 |
case 'blocksconf':
|
| 170 |
$block = lmo_getblock($id);
|
| 171 |
drupal_set_title(t('Configure block').' '.'"'.$block['title'].'"');
|
| 172 |
$status = lmo_check_blockstatus($block, true);
|
| 173 |
if ($status['message'] != '') {
|
| 174 |
$form['error'] = array(
|
| 175 |
'#type' => 'markup',
|
| 176 |
'#value' => '<span class="error clear-block">'.$status['message'].'</span>',
|
| 177 |
);
|
| 178 |
}
|
| 179 |
$form['title'] = array(
|
| 180 |
'#type' => 'textfield',
|
| 181 |
'#title' => t('Title'),
|
| 182 |
'#description' => t('You can give your block any title you want'),
|
| 183 |
'#default_value' => $block['title'],
|
| 184 |
);
|
| 185 |
$form['intro'] = array(
|
| 186 |
'#type' => 'textarea',
|
| 187 |
'#title' => t('Introduction'),
|
| 188 |
'#description' => t('What should be shown above the lmo data?'),
|
| 189 |
'#default_value' => $block['intro'],
|
| 190 |
);
|
| 191 |
$form['conclusion'] = array(
|
| 192 |
'#type' => 'textarea',
|
| 193 |
'#title' => t('Conclusion'),
|
| 194 |
'#description' => t('What should be shown in the bottom of the lmo data?'),
|
| 195 |
'#default_value' => $block['intro'],
|
| 196 |
'#weight' => 30,
|
| 197 |
);
|
| 198 |
switch ($block['type']) {
|
| 199 |
case 'minitab':
|
| 200 |
require($lmo_path.'/init.php');
|
| 201 |
$dirliga = $lmo_path.'/'.$dirliga;
|
| 202 |
$dir = opendir($dirliga);
|
| 203 |
$files = array();
|
| 204 |
while ($file = readdir($dir)) {
|
| 205 |
if (substr($file, strlen($file)-4) == '.l98') $files[$file] = $file;
|
| 206 |
}
|
| 207 |
$form['option1'] = array(
|
| 208 |
'#type' => 'select',
|
| 209 |
'#title' => t('League file'),
|
| 210 |
'#description' => t('Give the league you want to show the standings for!'),
|
| 211 |
'#options' => $files,
|
| 212 |
'#return_value' => 1,
|
| 213 |
'#default_value' => $block['option1'],
|
| 214 |
);
|
| 215 |
$dir = opendir(PATH_TO_TEMPLATEDIR.'/mini');
|
| 216 |
$files2 = array();
|
| 217 |
while ($file = readdir($dir)) {
|
| 218 |
if (substr($file, strlen($file)-8) == '.tpl.php') {
|
| 219 |
$templatename = substr($file, 0, strlen($file)-8);
|
| 220 |
$files2[$templatename] = $templatename;
|
| 221 |
}
|
| 222 |
}
|
| 223 |
$form['option2'] = array(
|
| 224 |
'#type' => 'select',
|
| 225 |
'#title' => t('Template'),
|
| 226 |
'#description' => t('Give a template for the output!'),
|
| 227 |
'#options' => $files2,
|
| 228 |
'#return_value' => 1,
|
| 229 |
'#default_value' => $block['option2'],
|
| 230 |
);
|
| 231 |
$form['blockid'] = array('#type' => 'hidden', '#value' => $id);
|
| 232 |
$form['task'] = array('#type' => 'hidden', '#value' => 'blocksconf');
|
| 233 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 51);
|
| 234 |
$form['cancel'] = array('#type' => 'button', '#value' => t('Cancel'), '#weight' => 50);
|
| 235 |
break;
|
| 236 |
default:
|
| 237 |
$form['foo'] = array(
|
| 238 |
'#type' => 'markup',
|
| 239 |
'#value' => t('There is an error with the configuration of the block so you can\'t do nothing here.').' ',
|
| 240 |
);
|
| 241 |
$form['foo2'] = array(
|
| 242 |
'#type' => 'markup',
|
| 243 |
'#value' => l(t('Go back to lmo blocks list here!'), 'admin/content/lmo/drupal/blocks'),
|
| 244 |
);
|
| 245 |
}
|
| 246 |
break;
|
| 247 |
default:
|
| 248 |
$form['foo'] = array(
|
| 249 |
'#type' => 'markup',
|
| 250 |
'#value' => t('Here should some options appear soon.'),
|
| 251 |
);
|
| 252 |
};
|
| 253 |
return $form;
|
| 254 |
}
|
| 255 |
|
| 256 |
function lmo_admin_integration_form_submit($form, &$form_state) {
|
| 257 |
$form_values = $form_state['values'];
|
| 258 |
$lmo_path= variable_get('lmo_local_path','');
|
| 259 |
switch ($form_values['task']) {
|
| 260 |
case 'blocksadd':
|
| 261 |
$type = 'undefined';
|
| 262 |
switch ($form_values['blocktype']) {
|
| 263 |
case 0:
|
| 264 |
$type = 'minitab';
|
| 265 |
break;
|
| 266 |
case 1:
|
| 267 |
$type = 'chart';
|
| 268 |
break;
|
| 269 |
}
|
| 270 |
db_query("INSERT INTO {lmo_blocks} SET type='".$type."', title='thisnewblock'");
|
| 271 |
$result = db_query("SELECT * FROM {lmo_blocks} WHERE title='thisnewblock'");
|
| 272 |
$blockdata = db_fetch_object($result);
|
| 273 |
db_query("UPDATE {lmo_blocks} SET title = '".$form_values['title']."' WHERE id='".$blockdata->id."'");
|
| 274 |
drupal_set_message('Created the block "'.$form_values['title'].'". Please configure the content now!');
|
| 275 |
drupal_goto('admin/content/lmo/drupal/blocks/conf/'.$blockdata->id);
|
| 276 |
break;
|
| 277 |
case 'blocksdelete':
|
| 278 |
db_query("DELETE FROM {lmo_blocks} WHERE id='".$form_values['blockid']."'");
|
| 279 |
db_query("DELETE FROM {blocks} WHERE delta='".$form_values['blockid']."' AND module='lmo'");
|
| 280 |
drupal_set_message(t('Deleted block'). ' '.$form_values['blockid']);
|
| 281 |
drupal_goto('admin/content/lmo/drupal/blocks');
|
| 282 |
break;
|
| 283 |
case 'blocksconf':
|
| 284 |
db_query("UPDATE {lmo_blocks} SET
|
| 285 |
option1='".$form_values['option1']."',
|
| 286 |
option2='".$form_values['option2']."',
|
| 287 |
intro='".$form_values['intro']."',
|
| 288 |
conclusion='".$form_values['conclusion']."',
|
| 289 |
title='".$form_values['title']."' WHERE id='".$form_values['blockid']."'");
|
| 290 |
drupal_set_message(t('Saved block configuration'));
|
| 291 |
drupal_goto('admin/content/lmo/drupal/blocks');
|
| 292 |
break;
|
| 293 |
}
|
| 294 |
|
| 295 |
}
|