Пример #1
0
/**
 * Creates and displays (or returns) a buttons to a popup window.
 *
 * @deprecated since Moodle 2.0
 *
 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
 * @param string $name Name to be assigned to the popup window (this is used by
 *   client-side scripts to "talk" to the popup window)
 * @param string $linkname Text to be displayed as web link
 * @param int $height Height to assign to popup window
 * @param int $width Height to assign to popup window
 * @param string $title Text to be displayed as popup page title
 * @param string $options List of additional options for popup window
 * @param bool $return If true, return as a string, otherwise print
 * @param string $id id added to the element
 * @param string $class class added to the element
 * @return string html code to display a link to a popup window.
 */
function button_to_popup_window($url, $name = null, $linkname = null, $height = 400, $width = 500, $title = null, $options = null, $return = false, $id = null, $class = null)
{
    global $OUTPUT;
    debugging('button_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->button().');
    if ($options == 'none') {
        $options = null;
    }
    if (empty($linkname)) {
        throw new coding_exception('A link must have a descriptive text value! See $OUTPUT->link_to_popup() for usage.');
    }
    // Create a html_button object
    $form = new html_form();
    $form->button->text = $linkname;
    $form->button->title = $title;
    $form->button->id = $id;
    $form->url = $url;
    $form->add_class($class);
    // Parse the $options string
    $popupparams = array();
    if (!empty($options)) {
        $optionsarray = explode(',', $options);
        foreach ($optionsarray as $option) {
            if (strstr($option, '=')) {
                $parts = explode('=', $option);
                if ($parts[1] == '0') {
                    $popupparams[$parts[0]] = false;
                } else {
                    $popupparams[$parts[0]] = $parts[1];
                }
            } else {
                $popupparams[$option] = true;
            }
        }
    }
    if (!empty($height)) {
        $popupparams['height'] = $height;
    }
    if (!empty($width)) {
        $popupparams['width'] = $width;
    }
    $form->button->add_action(new popup_action('click', $url, $name, $popupparams));
    $output = $OUTPUT->button($form);
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}