00001 <?php
00002
00011 function area_banner_menu() {
00012
00013 $items = array();
00014
00015 $items['admin/settings/area_banner'] = array(
00016 'title' => 'Area Banner',
00017 'description' => 'Upload banners and define when they shall be displayed.',
00018 'page callback' => 'drupal_get_form',
00019 'page arguments' => array('area_banner_config'),
00020 'access arguments' => array('config area_banner'),
00021 'type' => MENU_NORMAL_ITEM,
00022 );
00023 $items['admin/settings/area_banner/delete_default'] = array(
00024 'page callback' => 'area_banner_delete_default',
00025 'access arguments' => array('config area_banner'),
00026 'type' => MENU_CALLBACK,
00027 );
00028 $items['admin/settings/area_banner/delete_flashdefault'] = array(
00029 'page callback' => 'area_banner_delete_flashdefault',
00030 'access arguments' => array('config area_banner'),
00031 'type' => MENU_CALLBACK,
00032 );
00033
00034 return $items;
00035 }
00036
00037
00041 function area_banner_perm() {
00042 return array('config area_banner');
00043
00044 }
00045
00049 function area_banner_delete_default() {
00050 variable_del('area_default_banner_path');
00051 drupal_goto('admin/settings/area_banner');
00052 }
00053
00057 function area_banner_delete_flashdefault() {
00058 variable_del('area_default_banner_flashpath');
00059 db_query("DELETE FROM {variable} WHERE name LIKE '%s'", 'area_default_banner_flashpath%');
00060 drupal_goto('admin/settings/area_banner');
00061 }
00062
00063
00067 function area_banner_block($op = 'list', $delta = 0) {
00068
00069 if ($op == "list") {
00070 $block[0]["info"] = t('Area Banner');
00071 return $block;
00072 }
00073 else if ($op == 'configure') {
00074
00075 }
00076 else if ($op == 'save') {
00077
00078 }
00079 else if ($op == 'view') {
00080
00081 $tmp_menu = menu_get_active_menu_name();
00082 menu_set_active_menu_name(variable_get('area_banner_active_menu',''));
00083 $active_trail = menu_get_active_trail();
00084 menu_set_active_menu_name($tmp_menu);
00085
00086 $banner_sets = variable_get('area_banner_sets',array());
00087 $active_banner=array('file' => '','depth' => -1);
00088 foreach ($banner_sets as $key => $set) {
00089
00090 $menu_name = strtok($set['menu'],':');
00091 $mlid = strtok(':');
00092 $path = $set['file'];
00093
00094 $depth=0;
00095
00096 foreach($active_trail as $menu_item){
00097
00098 if (is_array($menu_item) && array_key_exists('mlid',$menu_item)
00099 && $menu_item['mlid'] == $mlid
00100 && $depth > $active_banner['depth'])
00101 {
00102 $active_banner = array(
00103 'file' => $path,
00104 'depth' => $depth,
00105 );
00106 break;
00107 }
00108 $depth++;
00109 }
00110 }
00111
00112
00113 if (empty($active_banner['file']['flashpath']) && empty($active_banner['file']['filepath']) ){
00114 $active_banner['file']['filepath'] = variable_get('area_default_banner_path','');
00115 $active_banner['file']['flashpath'] = variable_get('area_default_banner_flashpath','');
00116 }
00117
00118 $block = array();
00119 $block['subject'] = '';
00120
00121 if(!empty($active_banner['file']['flashpath'])){
00122 $block['content']=swf('area_banners/'.$active_banner['file']['flashpath'],
00123 array('othervars' => array(
00124 'html_alt' => '<img src="' .file_create_url($active_banner['file']['filepath']) . '" alt="Replacement image used when flash does not load"/>'
00125 )
00126 )
00127 );
00128 }
00129 else if(!empty($active_banner['file']['filepath'])){
00130 $block['content']='<img src="' . file_create_url($active_banner['file']['filepath']) . '">';
00131 }
00132 else
00133 $block['content']='';
00134
00135 return $block;
00136 }
00137 }
00138
00139
00140
00144 function area_banner_config() {
00145 global $conf;
00146
00147
00148
00149 db_query("DELETE FROM {variable} WHERE name LIKE '%s'", 'area_banner_file%');
00150 db_query("DELETE FROM {variable} WHERE name LIKE '%s'", 'area_banner_menu%');
00151 db_query("DELETE FROM {variable} WHERE name LIKE '%s'", 'area_banner_path%');
00152
00153 db_query("DELETE FROM {variable} WHERE name LIKE '%s'", 'area_banner_flash%');
00154 db_query("DELETE FROM {variable} WHERE name LIKE '%s'", 'area_banner_flashpath%');
00155 cache_clear_all('variables', 'cache');
00156
00157 while (list($key, $val) = each($conf)) {
00158 if (strpos($key,'area_banner_file') !== FALSE){
00159 unset($conf[$key]);
00160 }
00161 if (strpos($key,'area_banner_menu') !== FALSE){
00162 unset($conf[$key]);
00163 }
00164 if (strpos($key,'area_banner_path') !== FALSE){
00165 unset($conf[$key]);
00166 }
00167 if (strpos($key,'area_banner_flashpath') !== FALSE){
00168 unset($conf[$key]);
00169 }
00170 }
00171
00172
00173 $item['mlid'] = 0;
00174 $selected_menu = variable_get('area_banner_active_menu','');
00175 $tree = menu_parent_options(empty($selected_menu)?menu_get_menus():array($selected_menu => $selected_menu), $item);
00176 array_unshift($tree,"<none>");
00177
00178 $banner_sets = variable_get('area_banner_sets',array());
00179 $set_counter=0;
00180
00181 $menus = menu_get_names();
00182 $menus = array_combine($menus,$menus);
00183
00184 $form['area_banner_active_menu'] = array(
00185 '#type' => 'select',
00186 '#size' => 1,
00187 '#title' => t('Active Menu'),
00188 '#default_value' => variable_get('area_banner_active_menu',''),
00189 '#options' => $menus,
00190 '#description' => t('Select the active menu. To see which page is in which area, this menu is searched. All areas have to be in this menu.'),
00191 );
00192
00193
00194
00195
00196 $banner_path = variable_get('area_default_banner_path','');
00197 $flash_path = variable_get('area_default_banner_flashpath','');
00198
00199 $form['area_banner_default_set'] = array(
00200 '#type' => 'fieldset',
00201 '#title' => t('Default Banner '),
00202 '#collapsible' => FALSE,
00203 '#collapsed' => FALSE,
00204 );
00205
00206
00207
00208
00209
00210 if (!empty($flash_path)){
00211 $form['area_banner_default_set']['area_default_banner_flashpath'] = array(
00212 '#type' => 'value',
00213 '#value' => $flash_path,
00214 );
00215 $form['area_banner_default_set']['area_default_banner_flash_display'] = array(
00216 '#type' => 'item',
00217 '#title' => t('Flash Banner'),
00218 '#value' => swf('area_banners/'.$flash_path,
00219 array('othervars' => array(
00220 'html_alt' => '<img src="' .file_create_url($banner_path) . '" alt="Replacement image used when flash does not load"/>'
00221 )
00222 )
00223 )
00224 ,);
00225
00226 $form['area_banner_default_set']['area_delete_default_flashbanner'] = array(
00227 '#type' => 'item',
00228 '#value' => l('Delete Flash Banner','admin/settings/area_banner/delete_flashdefault')
00229 );
00230
00231 }
00232 if (!empty($banner_path)){
00233 $form['area_banner_default_set']['area_default_banner_path'] = array(
00234 '#type' => 'value',
00235 '#value' => $banner_path,
00236 );
00237 $form['area_banner_default_set']['area_default_banner_img_display'] = array(
00238 '#type' => 'item',
00239 '#title' => t('Banner'),
00240 '#value' => '<img src="' . file_create_url($banner_path) . '">',
00241 );
00242 $form['area_banner_default_set']['area_delete_default_banner'] = array(
00243 '#type' => 'item',
00244 '#value' => l('Delete Banner','admin/settings/area_banner/delete_default')
00245 );
00246 }
00247
00248 $form['area_banner_default_set']['area_default_banner_file'] = array(
00249 '#type' => 'file',
00250 '#title' => t('Upload new Image Banner'),
00251 '#size' => 40,
00252 );
00253
00254 $form['area_banner_default_set']['area_default_banner_flash'] = array(
00255 '#type' => 'file',
00256 '#title' => t('Upload new Flash Banner'),
00257 '#size' => 40,
00258 );
00259
00260
00261
00262 for($empty_sets = 0; $empty_sets < 2; $set_counter++)
00263 {
00264 if ($set = each($banner_sets)){
00265 $menu = $set['value']['menu'];
00266 $banner_path = $set['value']['file']['filepath'];
00267 $flash_path =$set['value']['file']['flashpath'];
00268 }
00269 if (empty($set['value']) || empty($set['value']['menu'])){
00270 $menu = '';
00271 $banner_path = '';
00272 $flash_path ='';
00273 $empty_sets++;
00274 }
00275
00276 $form['area_banner_set' . $set_counter] = array(
00277 '#type' => 'fieldset',
00278 '#title' => t('Banner ') . $set_counter,
00279 '#collapsible' => FALSE,
00280 '#collapsed' => FALSE,
00281 );
00282 $form['area_banner_set' . $set_counter]['area_banner_menu' . $set_counter] = array(
00283 '#type' => 'select',
00284 '#size' => 1,
00285 '#title' => t('Menu Items'),
00286 '#default_value' => $menu,
00287 '#options' => $tree,
00288 '#description' => t('Banner will appear on selected page and all it\'s children.'),
00289 );
00290
00291 if ($flash_path){
00292 $form['area_banner_set' . $set_counter]['area_banner_flashpath' . $set_counter] = array(
00293 '#type' => 'value',
00294 '#value' => $flash_path,
00295 );
00296 $form['area_banner_set' . $set_counter]['area_banner_flash_display' . $set_counter] = array(
00297 '#type' => 'item',
00298 '#title' => t('Flash banner'),
00299 '#value' => swf('area_banners/'.$flash_path,
00300 array('othervars' => array(
00301 'html_alt' => '<img src="' .file_create_url($banner_path) . '" alt="Replacement image used when flash does not load"/>'
00302 )
00303 )
00304 ),
00305 );
00306 }
00307 if ($banner_path){
00308 $form['area_banner_set' . $set_counter]['area_banner_path' . $set_counter] = array(
00309 '#type' => 'value',
00310 '#value' => $banner_path,
00311 );
00312 $form['area_banner_set' . $set_counter]['area_banner_img_display' . $set_counter] = array(
00313 '#type' => 'item',
00314 '#title' => t('Banner'),
00315 '#value' => '<img src="' . file_create_url($banner_path) . '">',
00316 );
00317 }
00318
00319
00320 $form['area_banner_set' . $set_counter]['area_banner_file' . $set_counter] = array(
00321 '#type' => 'file',
00322 '#title' => t('Upload new Image Banner'),
00323 '#size' => 40,
00324 );
00325 $form['area_banner_set'. $set_counter]['area_banner_flash'. $set_counter] = array(
00326 '#type' => 'file',
00327 '#title' => t('Upload new Flash Banner'),
00328 '#size' => 40,
00329 );
00330
00331 }
00332 $form['#attributes'] = array('enctype' => "multipart/form-data");
00333
00334 return system_settings_form($form);
00335 }
00336
00337
00338
00343 function area_banner_config_validate($form, &$form_state) {
00344
00345 $validators = array();
00346 $temp_dest=file_directory_temp();
00347 $dest = file_directory_path() . '/area_banners';
00348 file_check_directory($dest,TRUE);
00349
00350 $banner_sets=array();
00351 $set_counter=0;
00352 foreach ($form_state['values'] as $key => $value){
00353
00354
00355 if ($key == 'area_banner_menu' . $set_counter){
00356 $filepath = '';
00357 $flashpath ='';
00358
00359 if (array_key_exists('area_banner_path' . $set_counter, $form_state['values'])){
00360 $filepath = $form_state['values']['area_banner_path' . $set_counter];
00361 }
00362
00363 if (array_key_exists('area_banner_flashpath' . $set_counter, $form_state['values'])){
00364 $flashpath = $form_state['values']['area_banner_flashpath' . $set_counter];
00365 }
00366
00367
00368 if (array_key_exists('area_banner_file' . $set_counter, $_FILES['files']['name'])){
00369 $file = file_save_upload('area_banner_file' . $set_counter, $validators, $temp_dest);
00370
00371 if ($file !== 0) {
00372 $result = file_copy($file, $dest, FILE_EXISTS_RENAME);
00373 if ($result == 1) {
00374 $filepath = $file->filepath;
00375 }
00376 }
00377 }
00378
00379
00380 if (array_key_exists('area_banner_flash' . $set_counter, $_FILES['files']['name'])){
00381 $file = file_save_upload('area_banner_flash' . $set_counter, $validators, $temp_dest);
00382
00383 if ($file !== 0) {
00384 $result = file_copy($file, $dest, FILE_EXISTS_RENAME);
00385 if ($result == 1) {
00386 $flashpath = $file->filename;
00387 }
00388 }
00389 }
00390
00391
00392 if (!empty($filepath) && !empty($flashpath)){
00393 $banner_sets[] = array(
00394 "menu" => $form_state['values']['area_banner_menu' . $set_counter],
00395 "file" => array("flashpath" => $flashpath, "filepath" => $filepath)
00396 );
00397 }
00398 else if(!empty($flashpath)){
00399 $banner_sets[] = array(
00400 "menu" => $form_state['values']['area_banner_menu' . $set_counter],
00401 "file" => array("flashpath" => $flashpath)
00402 );
00403 }
00404 else if(!empty($filepath)){
00405 $banner_sets[] = array(
00406 "menu" => $form_state['values']['area_banner_menu' . $set_counter],
00407 "file" => array("filepath" => $filepath)
00408 );
00409 }
00410 $set_counter++;
00411 }
00412 }
00413
00414
00415
00416 $filepath = '';
00417 $flashpath = '';
00418
00419 if (array_key_exists('area_default_banner_path', $form_state['values'])){
00420 $filepath = $form_state['values']['area_default_banner_path'];
00421 }
00422
00423
00424 if (array_key_exists('area_default_banner_flashpath', $form_state['values'])){
00425 $flashpath = $form_state['values']['area_default_banner_flashpath'];
00426 }
00427
00428
00429 if (array_key_exists('area_default_banner_file', $_FILES['files']['name'])){
00430 $file = file_save_upload('area_default_banner_file', $validators, $temp_dest);
00431
00432 if ($file !== 0) {
00433 $result = file_copy($file, $dest, FILE_EXISTS_RENAME);
00434 if ($result == 1) {
00435 variable_set('area_default_banner_path',$file->filepath);
00436 }
00437 }
00438 }
00439
00440 if (array_key_exists('area_default_banner_flash', $_FILES['files']['name'])){
00441 $file = file_save_upload('area_default_banner_flash', $validators, $temp_dest);
00442
00443 if ($file !== 0) {
00444 $result = file_copy($file, $dest, FILE_EXISTS_RENAME);
00445 if ($result == 1) {
00446 variable_set('area_default_banner_flashpath',$file->filename);
00447 }
00448 }
00449 }
00450
00451 variable_set('area_banner_sets',$banner_sets);
00452 }