array( check_plain($row->name), check_plain($row->link), pageear_get_options('peelPosition', $row->peelPosition), !$row->status ? l(t('enable'), 'admin/build/pageear/'. $row->peid .'/enable') : l(t('disable'), 'admin/build/pageear/'. $row->peid .'/disable'), l(t('clone'), 'admin/build/pageear/'. $row->peid .'/clone'), l(t('configure'), 'admin/build/pageear/'. $row->peid .'/configure'), l(t('delete'), 'admin/build/pageear/'. $row->peid .'/delete'), ), 'class' => $row->status ? 'enabled' : 'disabled', ); } $header = array(t('Pageear'), t('Link'), t('Position'), array('data' => t('Operations'), 'colspan' => '4')); return theme('table', $header, $rows, $attributes = array('class' => 'pageear-admin-list'), NULL); } /** * Menu callback; displays the pageear configuration form. * * Using the same form for three different operations ($op): * - 'configure': configure an existing pageear (default) * - 'add': add a new pageear * - 'clone': clone an existing pageear */ function pageear_admin_configure($form_state, $pageear, $op = 'configure') { if ($op == 'add' || !$pageear->peid) { $pageear = pageear_get_default(); } if ($op == 'clone') { $pageear->peid = 0; } $form = array(); $form['#attributes'] = array('enctype' => "multipart/form-data"); $form['peid'] = array( '#type' => 'value', '#value' => $pageear->peid, ); // Info $form['info'] = array( '#type' => 'fieldset', '#title' => t('Pageear info'), '#collapsible' => TRUE, ); $form['info']['status'] = array( '#type' => 'checkbox', '#title' => t('Enable pageear'), '#default_value' => $pageear->status, '#description' => t('If this setting is enabled, the current pageear is shown on the configured pages (see specific options below).'), ); $form['info']['name'] = array( '#type' => 'textfield', '#title' => t('Pageear name'), '#default_value' => $pageear->name, '#description' => t('The name of the pageear.'), '#required' => TRUE, '#maxlength' => 64, ); // End Info // Details $form['details'] = array( '#type' => 'fieldset', '#title' => t('Pageear details'), '#collapsible' => TRUE, ); // Position settings. $form['details']['position_settings'] = array( '#type' => 'fieldset', '#title' => t('Position Settings'), '#collapsible' => TRUE, ); // Set direction of pageear in left or right top browser corner ( topleft: left | topright: right ). $form['details']['position_settings']['peelPosition'] = array( '#type' => 'radios', '#title' => t('Corner'), '#description' => t('In what corner the ad will be displayed.'), '#options' => pageear_get_options('peelPosition'), '#default_value' => $pageear->peelPosition, '#required' => TRUE, ); // End Position settings. // Image Settings. $form['details']['image_settings'] = array( '#type' => 'fieldset', '#title' => t('Image Settings'), '#collapsible' => TRUE, ); // URL to small image. $form['details']['image_settings']['smallURL'] = array( '#type' => 'textfield', '#title' => t('Unpeeled image'), '#description' => t('URL of image to show when the ad is not peeled (JPEG, GIF or PNG 100x100 pixels).'), '#required' => TRUE, '#default_value' => $pageear->smallURL, '#maxlength' => 255, ); $form['details']['image_settings']['smallURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an image to show when the ad is not peeled.'), '#tree' => FALSE, ); // URL to big image. $form['details']['image_settings']['bigURL'] = array( '#type' => 'textfield', '#title' => t('Peeled image'), '#description' => t('URL of the image to show when the ad is peeled (JPEG, GIF or PNG 500x500 pixels).'), '#required' => TRUE, '#default_value' => $pageear->bigURL, '#maxlength' => 255, ); $form['details']['image_settings']['bigURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an image to show when the ad is peeled.'), '#tree' => FALSE, ); // Mirror image ( true | false ). $form['details']['image_settings']['mirror'] = array( '#type' => 'checkbox', '#title' => t('Back mirror'), '#default_value' => $pageear->mirror, '#description' => t('Mirror the ad on the back of the peeled page.'), ); // In Transition for pageear. $form['details']['image_settings']['inTransition'] = array( '#type' => 'select', '#title' => t('In Transition'), '#description' => t('In Transition for the pageear.'), '#options' => pageear_get_options('inTransition'), '#default_value' => $pageear->inTransition, '#required' => TRUE, ); // Duration of in transition (1-9). $form['details']['image_settings']['transitionDuration'] = array( '#type' => 'textfield', '#title' => t('Transition Duration'), '#description' => t('Duration of in transition. (1-9)'), '#required' => TRUE, '#default_value' => $pageear->transitionDuration, '#maxlength' => 1, ); // Color of peel back. $form['details']['image_settings']['peelColor'] = array( '#type' => 'radios', '#title' => t('Back color'), '#description' => t('This color will be used on the back of peel.'), '#options' => pageear_get_options('peelColor'), '#default_value' => $pageear->peelColor, '#required' => TRUE, ); // Custom color. $form['details']['image_settings']['custom_color'] = array( '#type' => 'fieldset', '#title' => t('Custom Color'), '#collapsible' => TRUE, ); // Red Value for Custom Color Peel. $form['details']['image_settings']['custom_color']['redValue'] = array( '#type' => 'textfield', '#title' => t('Red Value'), '#description' => t('Red Value of Custom Color Peel (0-255).'), '#required' => TRUE, '#default_value' => $pageear->redValue, '#maxlength' => 3, ); // Green Value for Custom Color Peel. $form['details']['image_settings']['custom_color']['greenValue'] = array( '#type' => 'textfield', '#title' => t('Green Value'), '#description' => t('Green Value of Custom Color Peel (0-255).'), '#required' => TRUE, '#default_value' => $pageear->greenValue, '#maxlength' => 3, ); // Blue Value for Custom Color Peel. $form['details']['image_settings']['custom_color']['blueValue'] = array( '#type' => 'textfield', '#title' => t('Blue Value'), '#description' => t('Blue Value of Custom Color Peel (0-255).'), '#required' => TRUE, '#default_value' => $pageear->blueValue, '#maxlength' => 3, ); // End Image Settings. // Sound Settings. $form['details']['sound_settings'] = array( '#type' => 'fieldset', '#title' => t('Sound Settings'), '#collapsible' => TRUE, ); // URL to onload sound. $form['details']['sound_settings']['loadSoundURL'] = array( '#type' => 'textfield', '#title' => t('Onload Sound'), '#description' => t('URL of mp3 file to play when the ad is loaded.'), '#default_value' => $pageear->loadSoundURL, '#maxlength' => 255, ); $form['details']['sound_settings']['loadSoundURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an mp3 file to play when the ad is loaded.'), '#tree' => FALSE, ); // URL to open peel sound. $form['details']['sound_settings']['openSoundURL'] = array( '#type' => 'textfield', '#title' => t('Open Peel Sound'), '#description' => t('URL of mp3 file to play when the peel is opened.'), '#default_value' => $pageear->openSoundURL, '#maxlength' => 255, ); $form['details']['sound_settings']['openSoundURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an mp3 file to play when the peel is opened.'), '#tree' => FALSE, ); // URL to close peel sound. $form['details']['sound_settings']['closeSoundURL'] = array( '#type' => 'textfield', '#title' => t('Close Peel Sound'), '#description' => t('URL of mp3 file to play when the peel is closed.'), '#default_value' => $pageear->closeSoundURL, '#maxlength' => 255, ); $form['details']['sound_settings']['closeSoundURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an mp3 file to play when the peel is closed.'), '#tree' => FALSE, ); // End Sound Settings. // Linking Settings. $form['details']['linking_settings'] = array( '#type' => 'fieldset', '#title' => t('URL Settings'), '#collapsible' => TRUE, ); // URL to open on pageear click. $form['details']['linking_settings']['link'] = array( '#type' => 'textfield', '#title' => t('URL'), '#description' => t('URL to go when user click on the ad.'), '#required' => TRUE, '#default_value' => $pageear->link, ); // Browser target (new) or self (self). $form['details']['linking_settings']['linkTarget'] = array( '#type' => 'radios', '#title' => t('URL target'), '#description' => t('Where to open the URL.'), '#options' => pageear_get_options('linkTarget'), '#default_value' => $pageear->linkTarget, '#required' => TRUE, ); //End Linking Settings. // Motion Settings. $form['details']['motion_settings'] = array( '#type' => 'fieldset', '#title' => t('Motion Settings'), '#collapsible' => TRUE, ); // Speed of flag movement (1-9). $form['details']['motion_settings']['flagSpeed'] = array( '#type' => 'textfield', '#title' => t('Flag motion speed'), '#description' => t('Speed for flag motion. (1-9)'), '#required' => TRUE, '#default_value' => $pageear->flagSpeed, '#maxlength' => 1, ); // Speed of peel movement (1-9). $form['details']['motion_settings']['peelSpeed'] = array( '#type' => 'textfield', '#title' => t('Peel motion speed'), '#description' => t('Speed for peel motion. (1-9)'), '#required' => TRUE, '#default_value' => $pageear->peelSpeed, '#maxlength' => 1, ); // Opens pageear automaticaly after configured seconds. $form['details']['motion_settings']['automaticOpen'] = array( '#type' => 'textfield', '#title' => t('Automatically peel on load'), '#description' => t('Unpeel automatically when the page loads after configured seconds. 0 means no automatically open.'), '#required' => TRUE, '#default_value' => $pageear->automaticOpen, '#maxlength' => 3, ); // Seconds until pageear close after automatically open. $form['details']['motion_settings']['automaticClose'] = array( '#type' => 'textfield', '#title' => t('Automatically unpeel'), '#description' => t('Automatically close after unpeeling after configured seconds. 0 means no automatically unpeel.'), '#required' => TRUE, '#default_value' => $pageear->automaticClose, '#maxlength' => 3, ); // End Motion Settings. // Close button settings. $form['details']['closebutton_settings'] = array( '#type' => 'fieldset', '#title' => t('Close Button Settings'), '#collapsible' => TRUE, ); // Clickable button on open peel ( true | false ). $form['details']['closebutton_settings']['close_button_enable'] = array( '#type' => 'checkbox', '#title' => t('Close Button'), '#default_value' => $pageear->close_button_enable, '#description' => t('Show a close button on open peel. If this is enabled the peel will not close on mouse out. Users must click button to close peel.'), ); // Text on close button. $form['details']['closebutton_settings']['text_on_close_button'] = array( '#type' => 'textfield', '#title' => t('Close Button Text'), '#description' => t('Text on clickable close button.'), '#required' => TRUE, '#default_value' => $pageear->text_on_close_button, ); // Close button color. $form['details']['closebutton_settings']['closebutton_color'] = array( '#type' => 'fieldset', '#title' => t('Close Button Color'), '#collapsible' => TRUE, ); // Close Button Color Red Value. $form['details']['closebutton_settings']['closebutton_color']['close_redValue'] = array( '#type' => 'textfield', '#title' => t('Red Value'), '#description' => t('Close Button Color Red Value (0-255).'), '#required' => TRUE, '#default_value' => $pageear->close_redValue, '#maxlength' => 3, ); // Close Button Color Green Value. $form['details']['closebutton_settings']['closebutton_color']['close_greenValue'] = array( '#type' => 'textfield', '#title' => t('Green Value'), '#description' => t('Close Button Color Green Value (0-255).'), '#required' => TRUE, '#default_value' => $pageear->close_greenValue, '#maxlength' => 3, ); // Close Button Color Blue Value. $form['details']['closebutton_settings']['closebutton_color']['close_blueValue'] = array( '#type' => 'textfield', '#title' => t('Blue Value'), '#description' => t('Close Button Color Blue Value (0-255).'), '#required' => TRUE, '#default_value' => $pageear->close_blueValue, '#maxlength' => 3, ); // End Close Button Settings. // Language-based visibility settings - only visible if 'locale' module enabled if (module_exists('locale')) { $form['language_vis_settings'] = array( '#type' => 'fieldset', '#title' => t('Language specific visibility settings'), '#collapsible' => TRUE, ); $language_options = locale_language_list('name'); $form['language_vis_settings']['languages'] = array( '#type' => 'checkboxes', '#title' => t('Show pageear for specific languages'), '#options' => $language_options, '#default_value' => explode(',', $pageear->languages), '#description' => t('Show the pageear only for the selected language(s). If you select no languages, the pageear will be visible for all languages.'), ); } // Role-based visibility settings (mostly borrowed from 'block.admin.inc') $result = db_query('SELECT rid, name FROM {role} ORDER BY name'); $role_options = array(); while ($role = db_fetch_object($result)) { $role_options[$role->rid] = $role->name; } $form['roles_vis_settings'] = array( '#type' => 'fieldset', '#title' => t('Role specific visibility settings'), '#collapsible' => TRUE, ); $form['roles_vis_settings']['roles'] = array( '#type' => 'checkboxes', '#title' => t('Show pageear for specific roles'), '#options' => $role_options, '#default_value' => explode(',', $pageear->roles), '#description' => t('Show the pageear only for the selected role(s). If you select no roles, the pageear will be visible to all users.'), ); $form['page_vis_settings'] = array( '#type' => 'fieldset', '#title' => t('Page specific visibility settings'), '#collapsible' => TRUE, ); $access = user_access('use PHP for pageear visibility'); if ($pageear->visibility == 2 && !$access) { $form['page_vis_settings'] = array(); $form['page_vis_settings']['visibility'] = array( '#type' => 'value', '#value' => 2, ); $form['page_vis_settings']['pages'] = array( '#type' => 'value', '#value' => $pageear->pages, ); } else { $options = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')); $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')); if ($access) { $options[] = t('Show if the following PHP code returns TRUE (PHP-mode, experts only).'); $description .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '')); } $form['page_vis_settings']['visibility'] = array( '#type' => 'radios', '#title' => t('Show pageear on specific pages'), '#options' => $options, '#default_value' => $pageear->visibility, ); $form['page_vis_settings']['pages'] = array( '#type' => 'textarea', '#title' => t('Pages'), '#default_value' => $pageear->pages, '#description' => $description, ); } if ($op == 'configure') { $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), ); $form['cancel'] = array( '#type' => 'markup', '#value' => l(t('Cancel'), referer_uri()), ); } else if ($op == 'add' || $op == 'clone') { $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), '#submit' => array('pageear_admin_add_submit'), ); $form['cancel'] = array( '#type' => 'markup', '#value' => l(t('Cancel'), referer_uri()), ); } return $form; } /** * hook_validate: validation function for the pageear configuration form. */ function pageear_admin_configure_validate($form, &$form_state) { $directory_path = file_directory_path() .'/'. PAGEEAR_PATH_IMAGES; // checks if directory exist and creates it if it don't file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path'); // uploads images from image upload fields foreach (array('smallURL', 'bigURL') as $image) { if ($file = file_save_upload($image .'_upload', array('file_validate_is_image' => array()))) { $parts = pathinfo($file->filename); if ($parts['extension'] != 'jpeg' && $parts['extension'] != 'jpg' && $parts['extension'] != 'gif' && $parts['extension'] != 'png') { form_set_error($image, t('Uploaded image must be an image file. JPEG, PNG or GIF')); } else { $filename = $directory_path .'/'. $image .'_'. $form_state['values']['peid'] .'.'. $parts['extension']; if (file_copy($file, $filename)) { $form_state['values'][$image] = $file->filepath; } } } } // uploads images from sound upload fields foreach (array('loadSoundURL', 'openSoundURL', 'closeSoundURL') as $sound) { if ($file = file_save_upload($sound .'_upload')) { $parts = pathinfo($file->filename); if ($parts['extension'] != 'mp3') { form_set_error($sound, t('Uploaded sound must be a MP3 file.')); } else { $filename = $directory_path .'/'. $sound .'_'. $form_state['values']['peid'] .'.'. $parts['extension']; if (file_copy($file, $filename)) { $form_state['values'][$sound] = $file->filepath; } } } } // Duration of transition validation if (!is_numeric($form_state['values']['transitionDuration']) || $form_state['values']['transitionDuration'] == 0) { form_set_error('transitionDuration', t('Transition duration must be a number between 1 and 9')); } // Peel custom color red value validation if (!is_numeric($form_state['values']['redValue']) || $form_state['values']['redValue'] < 0 || $form_state['values']['redValue'] > 255) { form_set_error('redValue', t('Custom color red value must be a number between 0 and 255')); } // Peel custom color green value validation if (!is_numeric($form_state['values']['greenValue']) || $form_state['values']['greenValue'] < 0 || $form_state['values']['greenValue'] > 255) { form_set_error('greenValue', t('Custom color green value must be a number between 0 and 255')); } // Peel custom color blue value validation if (!is_numeric($form_state['values']['blueValue']) || $form_state['values']['blueValue'] < 0 || $form_state['values']['blueValue'] > 255) { form_set_error('blueValue', t('Custom color blue value must be a number between 0 and 255')); } // Flag speed validation if (!is_numeric($form_state['values']['flagSpeed']) || $form_state['values']['flagSpeed'] == 0) { form_set_error('flagSpeed', t('Flag motion speed must be a number between 1 and 9')); } // Peel speed validation if (!is_numeric($form_state['values']['peelSpeed']) || $form_state['values']['peelSpeed'] == 0) { form_set_error('peelSpeed', t('Peel motion speed must be a number between 1 and 9')); } // AutomaticOpen validation if (!is_numeric($form_state['values']['automaticOpen']) || $form_state['values']['automaticOpen'] < 0) { form_set_error('automaticOpen', t('Automatically peel onload seconds must be a number between 0 and 999')); } // AutomaticClose validation if (!is_numeric($form_state['values']['automaticClose']) || $form_state['values']['automaticClose'] < 0) { form_set_error('automaticClose', t('Automatically peel onclose seconds must be a number between 0 and 999')); } // Close button color red value validation if (!is_numeric($form_state['values']['close_redValue']) || $form_state['values']['close_redValue'] < 0 || $form_state['values']['close_redValue'] > 255) { form_set_error('close_redValue', t('Close button color red value must be a number between 0 and 255')); } // Close button color green value validation if (!is_numeric($form_state['values']['close_greenValue']) || $form_state['values']['close_greenValue'] < 0 || $form_state['values']['close_greenValue'] > 255) { form_set_error('close_greenValue', t('Close button color green value must be a number between 0 and 255')); } // Close button color blue value validation if (!is_numeric($form_state['values']['close_blueValue']) || $form_state['values']['close_blueValue'] < 0 || $form_state['values']['close_blueValue'] > 255) { form_set_error('close_blueValue', t('Close button color blue value must be a number between 0 and 255')); } } /** * hook_submit: submit function for the pageear configuration form. */ function pageear_admin_configure_submit($form, &$form_state) { // Save the edited pageear if (!form_get_errors()) { if (module_exists('locale')) { $languages = implode(',', $form_state['values']['languages']); } else { $languages = ''; } $roles = implode(',', $form_state['values']['roles']); $sql = "UPDATE {pageears} SET"; $sql .= " status = '%d', name = '%s', peelPosition = '%s', smallURL = '%s', bigURL = '%s', mirror = '%d', inTransition = '%s', transitionDuration = '%d', peelColor = '%s', redValue = '%d', greenValue = '%d', blueValue = '%d', linkTarget = '%s', link = '%s', loadSoundURL = '%s', openSoundURL = '%s', closeSoundURL = '%s', flagSpeed = '%d', peelSpeed = '%d', automaticOpen = '%d', automaticClose = '%d', close_button_enable = '%d', text_on_close_button = '%s', close_redValue = '%d', close_greenValue = '%d', close_blueValue = '%d', languages = '%s', roles = '%s', visibility = '%d', pages = '%s'"; $sql .= " WHERE peid = %d"; db_query($sql, $form_state['values']['status'], $form_state['values']['name'], $form_state['values']['peelPosition'], $form_state['values']['smallURL'], $form_state['values']['bigURL'], $form_state['values']['mirror'], $form_state['values']['inTransition'], $form_state['values']['transitionDuration'], $form_state['values']['peelColor'], $form_state['values']['redValue'], $form_state['values']['greenValue'], $form_state['values']['blueValue'], $form_state['values']['linkTarget'], $form_state['values']['link'], $form_state['values']['loadSoundURL'], $form_state['values']['openSoundURL'], $form_state['values']['closeSoundURL'], $form_state['values']['flagSpeed'], $form_state['values']['peelSpeed'], $form_state['values']['automaticOpen'], $form_state['values']['automaticClose'], $form_state['values']['close_button_enable'], $form_state['values']['text_on_close_button'], $form_state['values']['close_redValue'], $form_state['values']['close_greenValue'], $form_state['values']['close_blueValue'], $languages, $roles, $form_state['values']['visibility'], $form_state['values']['pages'], $form_state['values']['peid'] ); drupal_set_message(t('The pageear %name has been saved.', array('%name' => $form_state['values']['name']))); $form_state['redirect'] = 'admin/build/pageear'; } return; } /** * hook_submit: when adding new pageear. */ function pageear_admin_add_submit($form, &$form_state) { if (module_exists('locale')) { $languages = implode(',', $form_state['values']['languages']); } else { $languages = ''; } $roles = implode(',', $form_state['values']['roles']); $sql = "INSERT INTO {pageears} (status, name, peelPosition, smallURL, bigURL, mirror, inTransition, transitionDuration, peelColor, redValue, greenValue, blueValue, linkTarget, link, loadSoundURL, openSoundURL, closeSoundURL, flagSpeed, peelSpeed, automaticOpen, automaticClose, close_button_enable, text_on_close_button, close_redValue, close_greenValue, close_blueValue, languages, roles, visibility, pages)"; $sql .= " VALUES ('%d', '%s', '%s', '%s', '%s', '%d', '%s', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%d', '%s')"; db_query($sql, $form_state['values']['status'], $form_state['values']['name'], $form_state['values']['peelPosition'], $form_state['values']['smallURL'], $form_state['values']['bigURL'], $form_state['values']['mirror'], $form_state['values']['inTransition'], $form_state['values']['transitionDuration'], $form_state['values']['peelColor'], $form_state['values']['redValue'], $form_state['values']['greenValue'], $form_state['values']['blueValue'], $form_state['values']['linkTarget'], $form_state['values']['link'], $form_state['values']['loadSoundURL'], $form_state['values']['openSoundURL'], $form_state['values']['closeSoundURL'], $form_state['values']['flagSpeed'], $form_state['values']['peelSpeed'], $form_state['values']['automaticOpen'], $form_state['values']['automaticClose'], $form_state['values']['close_button_enable'], $form_state['values']['text_on_close_button'], $form_state['values']['close_redValue'], $form_state['values']['close_greenValue'], $form_state['values']['close_blueValue'], $languages, $roles, $form_state['values']['visibility'], $form_state['values']['pages'] ); // Move any images or sounds // to reflect the peid on its names // get last used peid $last_used_peid = db_last_insert_id('pageears', 'peid'); $directory_path = file_directory_path() .'/'. PAGEEAR_PATH_IMAGES; foreach (array('smallURL', 'bigURL', 'loadSoundURL', 'openSoundURL', 'closeSoundURL') as $image_sound) { //if ($image_sound == 'smallURL' || $image_sound == 'bigURL') { // $extension = '.jpg'; //} //else { // $extension = '.mp3'; //} $stringparts = explode(".", $form_state['values'][$image_sound]); $extension = $stringparts[count($stringparts)-1]; $source_path = $form_state['values'][$image_sound]; if ($source_path != '') { $destination_path = $directory_path .'/'. $image_sound .'_'. $last_used_peid .'.'. $extension; file_copy($source_path, $destination_path, FILE_EXISTS_REPLACE); $sql = "UPDATE {pageears} SET"; $sql .= " ". $image_sound ." = '%s'"; $sql .= " WHERE peid = %d"; db_query($sql, $destination_path, $last_used_peid ); } } // Delete possible images sounds uploaded with peid=0 delete_images_sounds(0); drupal_set_message(t('The pageear %name has been created.', array('%name' => $form_state['values']['name']))); $form_state['redirect'] = 'admin/build/pageear'; return; } /** * Menu callback: disable a specific pageear. */ function pageear_admin_disable($pageear) { db_query("UPDATE {pageears} SET status = 0 WHERE peid = %d", $pageear->peid); drupal_goto('admin/build/pageear'); } /** * Menu callback: enable a specific pageear. */ function pageear_admin_enable($pageear) { db_query("UPDATE {pageears} SET status = 1 WHERE peid = %d", $pageear->peid); drupal_goto('admin/build/pageear'); } /** * Deletes images and sounds for specific pageear. */ function delete_images_sounds($peid) { $directory_path = file_directory_path() .'/'. PAGEEAR_PATH_IMAGES; // if the directory where files reside does not exists nothing to do if (!file_check_directory($directory_path)) { return; } foreach (array('smallURL', 'bigURL', 'loadSoundURL', 'openSoundURL', 'closeSoundURL') as $image_sound) { if ($image_sound == 'smallURL' || $image_sound == 'bigURL') { $extensions = array('.jpg', '.jpeg', '.gif', '.png'); } else { $extensions = array('.mp3'); } foreach ($extensions as $extension) { $filename = $directory_path .'/'. $image_sound .'_'. $peid; $filepath = $filename . $extension; file_delete($filepath); $i = 0; $filepath = $filename .'_'. $i . $extension; while (file_delete($filepath)) { $i += 1; $filepath = $filename .'_'. $i . $extension; } } } } /** * Menu callback; confirm deletion of a pageear. */ function pageear_admin_delete($form_state, $pageear) { $form['pageear'] = array('#type' => 'hidden', '#value' => serialize($pageear)); $params = array('%name' => $pageear->name); return confirm_form($form, t('Are you sure you want to delete the pageear %name?', $params), 'admin/build/pageear', NULL, t('Delete'), t('Cancel')); } function pageear_admin_delete_submit($form, &$form_state) { $pageear = unserialize($form_state['values']['pageear']); db_query('DELETE FROM {pageears} WHERE peid = %d', $pageear->peid); delete_images_sounds($pageear->peid); drupal_set_message(t('The pageear %name has been removed.', array('%name' => $pageear->name))); $form_state['redirect'] = 'admin/build/pageear'; return; }