コード例 #1
0
ファイル: edit.php プロジェクト: nigeldaley/moodle
 * Regular expression replacement section *
 ******************************************/
if ($data->addtemplate) {
    $possiblefields = $DB->get_records('data_fields', array('dataid' => $data->id), 'id');
    ///then we generate strings to replace
    foreach ($possiblefields as $eachfield) {
        $field = data_get_field($eachfield, $data);
        $patterns[] = "[[" . $field->field->name . "]]";
        $replacements[] = $field->display_add_field($rid);
        $patterns[] = "[[" . $field->field->name . "#id]]";
        $replacements[] = 'field_' . $field->field->id;
    }
    $newtext = str_ireplace($patterns, $replacements, $data->{$mode});
} else {
    //if the add template is not yet defined, print the default form!
    echo data_generate_default_template($data, 'addtemplate', $rid, true, false);
    $newtext = '';
}
echo $newtext;
echo '<div class="mdl-align"><input type="submit" name="saveandview" value="' . get_string('saveandview', 'data') . '" />';
if ($rid) {
    echo '&nbsp;<input type="submit" name="cancel" value="' . get_string('cancel') . '" onclick="javascript:history.go(-1)" />';
} else {
    if (!$data->maxentries || has_capability('mod/data:manageentries', $context) || data_numentries($data) < $data->maxentries - 1) {
        echo '&nbsp;<input type="submit" value="' . get_string('saveandadd', 'data') . '" />';
    }
}
echo '</div>';
echo $OUTPUT->box_end();
echo '</div></form>';
/// Finish the page
コード例 #2
0
ファイル: view.php プロジェクト: hatone/moodle
             data_print_template('singletemplate', $records, $data, $search, $page);
             echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl);
         } else {
             // List template
             $baseurl = 'view.php?d=' . $data->id . '&amp;';
             //send the advanced flag through the URL so it is remembered while paging.
             $baseurl .= 'advanced=' . $advanced . '&amp;';
             if (!empty($search)) {
                 $baseurl .= 'filter=1&amp;';
             }
             //pass variable to allow determining whether or not we are paging through results.
             $baseurl .= 'paging=' . $paging . '&amp;';
             echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl);
             if (empty($data->listtemplate)) {
                 echo $OUTPUT->notification(get_string('nolisttemplate', 'data'));
                 data_generate_default_template($data, 'listtemplate', 0, false, false);
             }
             echo $data->listtemplateheader;
             data_print_template('listtemplate', $records, $data, $search, $page);
             echo $data->listtemplatefooter;
             echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl);
         }
     }
 }
 $search = trim($search);
 if (empty($records)) {
     $records = array();
 }
 if ($mode == '' && !empty($CFG->enableportfolios)) {
     require_once $CFG->libdir . '/portfoliolib.php';
     $button = new portfolio_add_button();
コード例 #3
0
ファイル: lib.php プロジェクト: nottmoo/moodle
/**
 * function that takes in the current data, number of items per page,
 * a search string and prints a preference box in view.php
 *
 * This preference box prints a searchable advanced search template if
 *     a) A template is defined
 *  b) The advanced search checkbox is checked.
 *
 * @global object
 * @global object
 * @param object $data
 * @param int $perpage
 * @param string $search
 * @param string $sort
 * @param string $order
 * @param array $search_array
 * @param int $advanced
 * @param string $mode
 * @return void
 */
function data_print_preference_form($data, $perpage, $search, $sort='', $order='ASC', $search_array = '', $advanced = 0, $mode= ''){
    global $CFG, $DB, $PAGE, $OUTPUT;

    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    echo '<br /><div class="datapreferences">';
    echo '<form id="options" action="view.php" method="get">';
    echo '<div>';
    echo '<input type="hidden" name="d" value="'.$data->id.'" />';
    if ($mode =='asearch') {
        $advanced = 1;
        echo '<input type="hidden" name="mode" value="list" />';
    }
    echo '<label for="pref_perpage">'.get_string('pagesize','data').'</label> ';
    $pagesizes = array(2=>2,3=>3,4=>4,5=>5,6=>6,7=>7,8=>8,9=>9,10=>10,15=>15,
                       20=>20,30=>30,40=>40,50=>50,100=>100,200=>200,300=>300,400=>400,500=>500,1000=>1000);
    echo html_writer::select($pagesizes, 'perpage', $perpage, false, array('id'=>'pref_perpage'));
    echo '<div id="reg_search" style="display: ';
    if ($advanced) {
        echo 'none';
    }
    else {
        echo 'inline';
    }
    echo ';" >&nbsp;&nbsp;&nbsp;<label for="pref_search">'.get_string('search').'</label> <input type="text" size="16" name="search" id= "pref_search" value="'.s($search).'" /></div>';
    echo '&nbsp;&nbsp;&nbsp;<label for="pref_sortby">'.get_string('sortby').'</label> ';
    // foreach field, print the option
    echo '<select name="sort" id="pref_sortby">';
    if ($fields = $DB->get_records('data_fields', array('dataid'=>$data->id), 'name')) {
        echo '<optgroup label="'.get_string('fields', 'data').'">';
        foreach ($fields as $field) {
            if ($field->id == $sort) {
                echo '<option value="'.$field->id.'" selected="selected">'.$field->name.'</option>';
            } else {
                echo '<option value="'.$field->id.'">'.$field->name.'</option>';
            }
        }
        echo '</optgroup>';
    }
    $options = array();
    $options[DATA_TIMEADDED]    = get_string('timeadded', 'data');
    $options[DATA_TIMEMODIFIED] = get_string('timemodified', 'data');
    $options[DATA_FIRSTNAME]    = get_string('authorfirstname', 'data');
    $options[DATA_LASTNAME]     = get_string('authorlastname', 'data');
    if ($data->approval and has_capability('mod/data:approve', $context)) {
        $options[DATA_APPROVED] = get_string('approved', 'data');
    }
    echo '<optgroup label="'.get_string('other', 'data').'">';
    foreach ($options as $key => $name) {
        if ($key == $sort) {
            echo '<option value="'.$key.'" selected="selected">'.$name.'</option>';
        } else {
            echo '<option value="'.$key.'">'.$name.'</option>';
        }
    }
    echo '</optgroup>';
    echo '</select>';
    echo '<label for="pref_order" class="accesshide">'.get_string('order').'</label>';
    echo '<select id="pref_order" name="order">';
    if ($order == 'ASC') {
        echo '<option value="ASC" selected="selected">'.get_string('ascending','data').'</option>';
    } else {
        echo '<option value="ASC">'.get_string('ascending','data').'</option>';
    }
    if ($order == 'DESC') {
        echo '<option value="DESC" selected="selected">'.get_string('descending','data').'</option>';
    } else {
        echo '<option value="DESC">'.get_string('descending','data').'</option>';
    }
    echo '</select>';

    if ($advanced) {
        $checked = ' checked="checked" ';
    }
    else {
        $checked = '';
    }
    $PAGE->requires->js('/mod/data/data.js');
    echo '&nbsp;<input type="hidden" name="advanced" value="0" />';
    echo '&nbsp;<input type="hidden" name="filter" value="1" />';
    echo '&nbsp;<input type="checkbox" id="advancedcheckbox" name="advanced" value="1" '.$checked.' onchange="showHideAdvSearch(this.checked);" /><label for="advancedcheckbox">'.get_string('advancedsearch', 'data').'</label>';
    echo '&nbsp;<input type="submit" value="'.get_string('savesettings','data').'" />';

    echo '<br />';
    echo '<div class="dataadvancedsearch" id="data_adv_form" style="display: ';

    if ($advanced) {
        echo 'inline';
    }
    else {
        echo 'none';
    }
    echo ';margin-left:auto;margin-right:auto;" >';
    echo '<table class="boxaligncenter">';

    // print ASC or DESC
    echo '<tr><td colspan="2">&nbsp;</td></tr>';
    $i = 0;

    // Determine if we are printing all fields for advanced search, or the template for advanced search
    // If a template is not defined, use the deafault template and display all fields.
    if(empty($data->asearchtemplate)) {
        data_generate_default_template($data, 'asearchtemplate');
    }

    static $fields = NULL;
    static $isteacher;
    static $dataid = NULL;

    if (empty($dataid)) {
        $dataid = $data->id;
    } else if ($dataid != $data->id) {
        $fields = NULL;
    }

    if (empty($fields)) {
        $fieldrecords = $DB->get_records('data_fields', array('dataid'=>$data->id));
        foreach ($fieldrecords as $fieldrecord) {
            $fields[]= data_get_field($fieldrecord, $data);
        }

        $isteacher = has_capability('mod/data:managetemplates', $context);
    }

    // Replacing tags
    $patterns = array();
    $replacement = array();

    // Then we generate strings to replace for normal tags
    foreach ($fields as $field) {
        $fieldname = $field->field->name;
        $fieldname = preg_quote($fieldname, '/');
        $patterns[] = "/\[\[$fieldname\]\]/i";
        $searchfield = data_get_field_from_id($field->field->id, $data);
        if (!empty($search_array[$field->field->id]->data)) {
            $replacement[] = $searchfield->display_search_field($search_array[$field->field->id]->data);
        } else {
            $replacement[] = $searchfield->display_search_field();
        }
    }
    $fn = !empty($search_array[DATA_FIRSTNAME]->data) ? $search_array[DATA_FIRSTNAME]->data : '';
    $ln = !empty($search_array[DATA_LASTNAME]->data) ? $search_array[DATA_LASTNAME]->data : '';
    $patterns[]    = '/##firstname##/';
    $replacement[] = '<input type="text" size="16" name="u_fn" value="'.$fn.'" />';
    $patterns[]    = '/##lastname##/';
    $replacement[] = '<input type="text" size="16" name="u_ln" value="'.$ln.'" />';

    // actual replacement of the tags
    $newtext = preg_replace($patterns, $replacement, $data->asearchtemplate);

    $options = new stdClass();
    $options->para=false;
    $options->noclean=true;
    echo '<tr><td>';
    echo format_text($newtext, FORMAT_HTML, $options);
    echo '</td></tr>';

    echo '<tr><td colspan="4" style="text-align: center;"><br/><input type="submit" value="'.get_string('savesettings','data').'" /><input type="submit" name="resetadv" value="'.get_string('resetsettings','data').'" /></td></tr>';
    echo '</table>';
    echo '</div>';
    echo '</div>';
    echo '</form>';
    echo '</div>';
}
コード例 #4
0
ファイル: templates.php プロジェクト: mongo0se/moodle
                $event = \mod_data\event\template_updated::create(array('context' => $context, 'courseid' => $course->id, 'other' => array('dataid' => $data->id)));
                $event->trigger();
            }
        }
    }
} else {
    echo '<div class="template_heading">' . get_string('header' . $mode, 'data') . '</div>';
}
/// If everything is empty then generate some defaults
if (empty($data->addtemplate) and empty($data->singletemplate) and empty($data->listtemplate) and empty($data->rsstemplate)) {
    data_generate_default_template($data, 'singletemplate');
    data_generate_default_template($data, 'listtemplate');
    data_generate_default_template($data, 'addtemplate');
    data_generate_default_template($data, 'asearchtemplate');
    //Template for advanced searches.
    data_generate_default_template($data, 'rsstemplate');
}
editors_head_setup();
$format = FORMAT_HTML;
if ($mode === 'csstemplate' or $mode === 'jstemplate') {
    $disableeditor = true;
}
if ($disableeditor) {
    $format = FORMAT_PLAIN;
}
$editor = editors_get_preferred_editor($format);
$strformats = format_text_menu();
$formats = $editor->get_supported_formats();
foreach ($formats as $fid) {
    $formats[$fid] = $strformats[$fid];
}
コード例 #5
0
ファイル: lib.php プロジェクト: alexandru-elisei/moodle
 /**
  * Creates a field for a mod_data instance.
  * Currently, the field types in the ignoredfieldtypes array aren't supported.
  *
  * @param StdClass $record
  * @param mod_data $data
  * @return data_field_{type}
  */
 public function create_field(stdClass $record = null, $data = null)
 {
     $record = (array) $record;
     if (in_array($record['type'], $this->ignoredfieldtypes)) {
         throw new coding_exception('$record\'s type value must not be same as values in ignoredfieldtypes
                 in phpunit_util::create_field()');
         return false;
     }
     $this->databasefieldcount++;
     if (!isset($data->course)) {
         throw new coding_exception('course must be present in phpunit_util::create_field() $data');
     }
     if (!isset($data->id)) {
         throw new coding_exception('dataid must be present in phpunit_util::create_field() $data');
     } else {
         $record['dataid'] = $data->id;
     }
     if (!isset($record['type'])) {
         throw new coding_exception('type must be present in phpunit_util::create_field() $record');
     }
     if (!isset($record['required'])) {
         $record['required'] = 0;
     }
     if (!isset($record['name'])) {
         $record['name'] = "testField - " . $this->databasefieldcount;
     }
     if (!isset($record['description'])) {
         $record['description'] = " This is testField - " . $this->databasefieldcount;
     }
     if (!isset($record['param1'])) {
         if (in_array($record['type'], array('checkbox', 'menu', 'multimenu', 'radiobutton'))) {
             $record['param1'] = implode("\n", array('one', 'two', 'three', 'four'));
         } else {
             if ($record['type'] === 'text' || $record['type'] === 'url') {
                 $record['param1'] = 1;
             } else {
                 $record['param1'] = '';
             }
         }
     }
     if (!isset($record['param2'])) {
         if ($record['type'] === 'textarea') {
             $record['param2'] = 60;
         } else {
             $record['param2'] = '';
         }
     }
     if (!isset($record['param3'])) {
         if ($record['type'] === 'textarea') {
             $record['param3'] = 35;
         } else {
             $record['param3'] = '';
         }
     }
     if (!isset($record['param4'])) {
         if ($record['type'] === 'textarea') {
             $record['param4'] = 1;
         }
     }
     if (!isset($record['param5'])) {
         if ($record['type'] === 'textarea') {
             $record['param5'] = 0;
         }
     }
     $record = (object) $record;
     $field = data_get_field($record, $data);
     $field->insert_field();
     data_generate_default_template($data, 'addtemplate', 0, false, true);
     return $field;
 }
コード例 #6
0
ファイル: lib.php プロジェクト: BackupTheBerlios/samouk-svn
function data_print_preference_form($data, $perpage, $search, $sort = '', $order = 'ASC', $search_array = '', $advanced = 0, $mode = '')
{
    global $CFG;
    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    echo '<br /><div class="datapreferences">';
    echo '<form id="options" action="view.php" method="get">';
    echo '<div>';
    echo '<input type="hidden" name="d" value="' . $data->id . '" />';
    if ($mode == 'asearch') {
        $advanced = 1;
        echo '<input type="hidden" name="mode" value="list" />';
    }
    echo '<label for="pref_perpage">' . get_string('pagesize', 'data') . '</label> ';
    $pagesizes = array(2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 100 => 100, 200 => 200, 300 => 300, 400 => 400, 500 => 500, 1000 => 1000);
    choose_from_menu($pagesizes, 'perpage', $perpage, '', '', '0', false, false, 0, 'pref_perpage');
    echo '<div id="reg_search" style="display: ';
    if ($advanced) {
        echo 'none';
    } else {
        echo 'inline';
    }
    echo ';" >&nbsp;&nbsp;&nbsp;<label for="pref_search">' . get_string('search') . '</label> <input type="text" size="16" name="search" id= "pref_search" value="' . s($search) . '" /></div>';
    echo '&nbsp;&nbsp;&nbsp;<label for="pref_sortby">' . get_string('sortby') . '</label> ';
    //foreach field, print the option
    $fields = get_records('data_fields', 'dataid', $data->id, 'name');
    echo '<select name="sort" id="pref_sortby"><option value="0">' . get_string('dateentered', 'data') . '</option>';
    foreach ($fields as $field) {
        if ($field->id == $sort) {
            echo '<option value="' . $field->id . '" selected="selected">' . $field->name . '</option>';
        } else {
            echo '<option value="' . $field->id . '">' . $field->name . '</option>';
        }
    }
    echo '</select>';
    echo '<label for="pref_order" class="accesshide">' . get_string('order') . '</label>';
    echo '<select id="pref_order" name="order">';
    if ($order == 'ASC') {
        echo '<option value="ASC" selected="selected">' . get_string('ascending', 'data') . '</option>';
    } else {
        echo '<option value="ASC">' . get_string('ascending', 'data') . '</option>';
    }
    if ($order == 'DESC') {
        echo '<option value="DESC" selected="selected">' . get_string('descending', 'data') . '</option>';
    } else {
        echo '<option value="DESC">' . get_string('descending', 'data') . '</option>';
    }
    echo '</select>';
    if ($advanced) {
        $checked = ' checked="checked" ';
    } else {
        $checked = '';
    }
    print '
            
        <script type="text/javascript">
        //<![CDATA[
        <!-- Start
        // javascript for hiding/displaying advanced search form

        function showHideAdvSearch(checked) {
            var divs = document.getElementsByTagName(\'div\');
            for(i=0;i<divs.length;i++) {
                if(divs[i].id.match(\'data_adv_form\')) {
                    if(checked) {
                        divs[i].style.display = \'inline\';
                    }
                    else {
                        divs[i].style.display = \'none\';
                    }
                }
                else if (divs[i].id.match(\'reg_search\')) {
                    if (!checked) {
                        divs[i].style.display = \'inline\';
                    }
                    else {
                        divs[i].style.display = \'none\';
                    }
                }
            }
        }
        //  End -->
        //]]>
        </script>';
    echo '&nbsp;<input type="checkbox" name="advanced" value="1" ' . $checked . ' onchange="showHideAdvSearch(this.checked);" />' . get_string('advancedsearch', 'data');
    echo '&nbsp;<input type="submit" value="' . get_string('savesettings', 'data') . '" />';
    echo '<br />';
    echo '<div class="dataadvancedsearch" id="data_adv_form" style="display: ';
    if ($advanced) {
        echo 'inline';
    } else {
        echo 'none';
    }
    echo ';margin-left:auto;margin-right:auto;" >';
    echo '<table class="boxaligncenter">';
    // print ASC or DESC
    echo '<tr><td colspan="2">&nbsp;</td></tr>';
    $i = 0;
    // Determine if we are printing all fields for advanced search, or the template for advanced search
    // If a template is not defined, use the deafault template and display all fields.
    if (empty($data->asearchtemplate)) {
        data_generate_default_template($data, 'asearchtemplate');
    }
    static $fields = NULL;
    static $isteacher;
    static $dataid = NULL;
    if (empty($dataid)) {
        $dataid = $data->id;
    } else {
        if ($dataid != $data->id) {
            $fields = NULL;
        }
    }
    if (empty($fields)) {
        $fieldrecords = get_records('data_fields', 'dataid', $data->id);
        foreach ($fieldrecords as $fieldrecord) {
            $fields[] = data_get_field($fieldrecord, $data);
        }
        $isteacher = has_capability('mod/data:managetemplates', $context);
    }
    /// Replacing tags
    $patterns = array();
    $replacement = array();
    /// Then we generate strings to replace for normal tags
    foreach ($fields as $field) {
        $patterns[] = '/\\[\\[' . $field->field->name . '\\]\\]/i';
        $searchfield = data_get_field_from_id($field->field->id, $data);
        if (!empty($search_array[$field->field->id]->data)) {
            $replacement[] = $searchfield->display_search_field($search_array[$field->field->id]->data);
        } else {
            $replacement[] = $searchfield->display_search_field();
        }
    }
    ///actual replacement of the tags
    $newtext = preg_replace($patterns, $replacement, $data->asearchtemplate);
    $options = new object();
    $options->para = false;
    $options->noclean = true;
    echo '<tr><td>';
    echo format_text($newtext, FORMAT_HTML, $options);
    echo '</td></tr>';
    echo '<tr><td colspan="4" style="text-align: center;"><br/><input type="submit" value="' . get_string('savesettings', 'data') . '" /><input type="reset" value="' . get_string('resetsettings', 'data') . '" /></td></tr>';
    echo '</table>';
    echo '</div>';
    echo '</div>';
    echo '</form>';
    echo '</div>';
}