// $Id$ /** * @file * A Test Module. */ /******************************************************************************* * Hook Functions (Drupal) ******************************************************************************/ /** * Display help and module information * @param path which path of the site we're displaying help * @param arg array that holds the current path as would be returned from arg() function * @return help text for the path */ function saacalendar_help($path, $arg) { //$output = '

'. t("test_module is a simple module to test functions and pages in Drupal"); // The line above outputs in ALL admin/module pages switch ($path) { case "admin/help/test_module": $output = '

'. t("test_module is a simple module to test functions and pages in Drupal") .'

'; break; } return $output; } // function saacalendar_help /** * Valid permissions for this module * @return array An array of valid permissions for the test_module module */ function saacalendar_perm() { return array('administer test_module', 'access test_module content'); } // function saacalendar_perm() /** * Menu for this module * @return array An array with this module's settings. */ function saacalendar_menu() { $items = array(); //Link to the test_module admin page: $items['admin/settings/test_module'] = array( 'title' => 'Test Module', 'description' => 'Administer Test Module Messages', 'page callback' => 'saacalendar_message', 'access arguments' => array('administer test_module'), 'type' => MENU_NORMAL_ITEM, ); return $items; } /** * Test Module Messages * @return array An array of form data. */ function saacalendar_message() { $page_content = ''; $page_content .= drupal_get_form('saacalendar_message_form'); $get_messages = db_query("SELECT * FROM {saacalendar_log} ORDER BY timestamp DESC"); if ($get_messages !== false) { $page_content .= "

Test Message Log

"; $row_count = 1; $id = 0; while($row = db_fetch_array($get_messages)) { $page_content .= "

"; foreach ($row as $key=>$value) { if ($key == 'id') $id = $value; if ($key == 'timestamp') $value = date('F j, Y G:i:s A', $value); if ($key == 'message') { if (strpos($value, 'eval:') !== false && $row_count === 1) { $value = trim(preg_replace('/eval:/', '', $value, 1)); eval($value); drupal_set_message(t("Executed code:\n").strval($value)); //Once the "eval:" code is evaluated, remove the "eval:" text to avoid executing the code again. db_query("UPDATE {saacalendar_log} SET message = '%s' WHERE id = %d", $value, $id); } $page_content .= "
\n"; } $page_content .= "".$key." = ".htmlspecialchars(strval($value))."  "; } $page_contents .= "

\n"; $row_count += 1; } } return $page_content; } /** * The callback function (form constructor) that creates the HTML form for saacalendar_message(). * @return form an array of form data. */ function saacalendar_message_form() { $form['saacalendar_message'] = array( '#type' => 'textarea', '#title' => t('Message'), '#default_value' => variable_get('saacalendar_message', 'Test Message'), '#cols' => 50, '#rows' => 5, '#description' => t("Enter a test message. Begin the message with \"eval:\" to execute PHPcode."), ); //Submit button: $form['submit'] = array( '#type' => 'submit', '#value' => t('Save Message'), ); return $form; } /** * Form validation for this module's settings * @param form an array that contains this module's settings * @param form_state an array that contains this module's settings */ function saacalendar_message_form_validate($form, &$form_state) { $saacalendar_message = $form_state['values']['saacalendar_message']; if (isset($saacalendar_message)) { if (!is_string($saacalendar_message) || $saacalendar_message == '') { form_set_error('saacalendar_message', t('Please enter a test message.')); } } } /** * Form submission for user data. * @param form an array that contains user data * @param form_state an array that contains user data */ function saacalendar_message_form_submit($form, &$form_state) { $test_message = $form_state['values']['saacalendar_message']; $exe_query = db_query("INSERT INTO {saacalendar_log} (timestamp, message) VALUES(%d, '%s')", time(), $test_message); $last_id = db_last_insert_id('{saacalendar_log}','id'); if ($exe_query !== false) { $msg = 'Added message to log: %id'; $vars = array('%id'=>$last_id); watchdog('test_module', $msg, $vars, WATCHDOG_INFO); drupal_set_message(t('Added message to log: ').strval($last_id)); } else { $msg = 'Could not add message to log: '; $vars = array(); watchdog('test_module', $msg, $vars, WATCHDOG_ERROR); drupal_set_message(t('Could not add message to log.')); } $form_state['redirect'] = 'admin/settings/test_module'; } Links Archers | Archery in Montrose

You are here


Login Required

Please log in to see the contents of this page