function filter_text_image($imagefile, $tex = "", $height = "", $width = "", $align = "middle", $alt = '') { global $CFG, $OUTPUT; if ($alt === '') { $alt = s($tex); } // Work out any necessary inline style. $rules = array(); if ($align !== 'middle') { $rules[] = 'vertical-align:' . $align . ';'; } if ($height) { $rules[] = 'height:' . $height . 'px;'; } if ($width) { $rules[] = 'width:' . $width . 'px;'; } if (!empty($rules)) { $style = ' style="' . implode('', $rules) . '" '; } else { $style = ''; } // Prepare the title attribute. if ($tex) { $tex = str_replace('&', '&', $tex); $tex = str_replace('<', '<', $tex); $tex = str_replace('>', '>', $tex); $tex = str_replace('"', '"', $tex); $tex = str_replace("\\'", ''', $tex); // Note that we retain the title tag as TeX format rather than using // the alt text, even if supplied. The alt text is intended for blind // users (to provide a text equivalent to the equation) while the title // is there as a convenience for sighted users who want to see the TeX // code. $title = "title=\"{$tex}\""; } // Build the output. $output = ""; if ($imagefile) { $anchorcontents = "<img class=\"texrender\" {$title} alt=\"{$alt}\" src=\""; if ($CFG->slasharguments) { // Use this method if possible for better caching $anchorcontents .= "{$CFG->wwwroot}/filter/tex/pix.php/{$imagefile}"; } else { $anchorcontents .= "{$CFG->wwwroot}/filter/tex/pix.php?file={$imagefile}"; } $anchorcontents .= "\" {$style}/>"; $link = $action = null; if (!file_exists("{$CFG->dataroot}/filter/tex/{$imagefile}") && has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { $link = '/filter/tex/texdebug.php'; } else { $link = '/filter/tex/displaytex.php?' . urlencode($tex); $action = new popup_action('click', $link, 'popup', array('height' => 300, 'width' => 240)); } $output .= $OUTPUT->action_link($link, $anchorcontents, $action, array('title' => 'TeX')); } else { $output .= "Error: must pass URL or course"; } return $output; }
/** * @return string */ public function getMessage() { if ($this->message !== null) { return $this->message; } return s('Must not be greater than "%s".', $this->max); }
function display_add_field($recordid = 0) { global $CFG, $DB; if ($recordid) { $content = trim($DB->get_field('data_content', 'content', array('fieldid' => $this->field->id, 'recordid' => $recordid))); } else { $content = ''; } $str = '<div title="' . s($this->field->description) . '">'; $str .= '<fieldset><legend><span class="accesshide">' . $this->field->name . '</span></legend>'; $i = 0; foreach (explode("\n", $this->field->param1) as $radio) { $radio = trim($radio); if ($radio === '') { continue; // skip empty lines } $str .= '<input type="radio" id="field_' . $this->field->id . '_' . $i . '" name="field_' . $this->field->id . '" '; $str .= 'value="' . s($radio) . '" '; if ($content == $radio) { // Selected by user. $str .= 'checked />'; } else { $str .= '/>'; } $str .= '<label for="field_' . $this->field->id . '_' . $i . '">' . $radio . '</label><br />'; $i++; } $str .= '</fieldset>'; $str .= '</div>'; return $str; }
/** * Function to export the renderer data in a format that is suitable for a * mustache template. This means: * 1. No complex types - only stdClass, array, int, string, float, bool * 2. Any additional info that is required for the template is pre-calculated (e.g. capability checks). * * This trait can be used as-is for simple form elements - or imported with a different name * so it can be extended with additional context variables before being returned. * * @param renderer_base $output Used to do a final render of any components that need to be rendered for export. * @return stdClass|array */ public function export_for_template(renderer_base $output) { $context = []; // Not all elements have all of these attributes - but they are common enough to be valid for a few. $standardattributes = ['id', 'name', 'label', 'multiple', 'checked', 'error', 'size', 'value']; $standardproperties = ['helpbutton', 'hiddenLabel']; // Standard attributes. foreach ($standardattributes as $attrname) { $value = $this->getAttribute($attrname); $context[$attrname] = $value; } // Standard class properties. foreach ($standardproperties as $propname) { $classpropname = '_' . $propname; $context[strtolower($propname)] = isset($this->{$classpropname}) ? $this->{$classpropname} : false; } $extraclasses = $this->getAttribute('class'); // Special wierd named property. $context['frozen'] = !empty($this->_flagFrozen); $context['hardfrozen'] = !empty($this->_flagFrozen) && empty($this->_persistantFreeze); // Other attributes. $otherattributes = []; foreach ($this->getAttributes() as $attr => $value) { if (!in_array($attr, $standardattributes) && $attr != 'class' && !is_object($value)) { $otherattributes[] = $attr . '="' . s($value) . '"'; } } $context['extraclasses'] = $extraclasses; $context['type'] = $this->getType(); $context['attributes'] = implode(' ', $otherattributes); return $context; }
public static function restore_data($data, $restore) { $linknamestatus = $linkurlstatus = false; foreach ($data as $datum) { switch ($datum->name) { case 'linkname': // We just want to know that it is there $linknamestatus = true; break; case 'linkurl': $content = $datum->value; $result = restore_decode_content_links_worker($content, $restore); if ($result != $content) { $datum->value = addslashes($result); if (debugging() and !defined('RESTORE_SILENTLY')) { echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />'; } $linkurlstatus = update_record('pagemenu_link_data', $datum); } else { $linkurlstatus = true; } break; default: debugging('Deleting unknown data type: ' . $datum->name); // Not recognized delete_records('pagemenu_link_data', 'id', $datum->id); break; } } return $linkurlstatus and $linknamestatus; }
function display_search_field($value = '') { global $CFG, $DB; if (is_array($value)) { $content = $value['checked']; $allrequired = $value['allrequired'] ? true : false; } else { $content = array(); $allrequired = false; } $str = ''; $found = false; foreach (explode("\n", $this->field->param1) as $checkbox) { $checkbox = trim($checkbox); if (in_array($checkbox, $content)) { $str .= html_writer::checkbox('f_' . $this->field->id . '[]', s($checkbox), true, $checkbox); } else { $str .= html_writer::checkbox('f_' . $this->field->id . '[]', s($checkbox), false, $checkbox); } $found = true; } if (!$found) { return ''; } $str .= html_writer::checkbox('f_' . $this->field->id . '_allreq', null, $allrequired, get_string('selectedrequired', 'data')); return $str; }
/** * Internal function - creates htmls structure suitable for YUI tree. */ protected function htmllize_tree($tree, $dir) { global $CFG; $yuiconfig = array(); $yuiconfig['type'] = 'html'; if (empty($dir['subdirs']) and empty($dir['files'])) { return ''; } $result = '<ul>'; foreach ($dir['subdirs'] as $subdir) { $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon')); $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>'; } foreach ($dir['files'] as $file) { $filename = $file->get_filename(); if ($CFG->enableplagiarism) { require_once($CFG->libdir.'/plagiarismlib.php'); $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course)); } else { $plagiarsmlinks = ''; } $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon')); $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>'; } $result .= '</ul>'; return $result; }
/** * Display the exception html */ public function getHtml() { if (req()->isAjax() || PHP_SAPI == "cli") { echo $this->getMessage() . "\n\n" . $this->getTraceAsString(); return; } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Error</title> </head> <body> <h1>Well, something is going wrong!</h1> <h3 style="color:red;"><?php echo nl2br(s($this->getMessage())); ?> </h3> <pre><?php echo $this->getTraceAsString(); ?> </pre> </body> </html> <?php }
/** Delete file controller */ public function __async_delete() { s()->async(true); /** @var \samsonphp\fs\FileService $fsModule */ $fsModule = m('fs'); /** @var \samsoncms\input\Field $field */ $this->createField(new dbQuery(), $_GET['e'], $_GET['f'], $_GET['i']); // Build uploaded file path $file = $this->field->value(); // Delete thumbnails if (class_exists('\\samson\\scale\\ScaleController', false) && $this->isImage($fsModule->extension($file))) { /** @var string $path Path to file */ $path = ''; // Get file path preg_match('/.*\\//', $file, $path); $path = $path[0]; // Get image src $src = substr($file, strlen($path)); /** @var \samson\scale\ScaleController $scale */ $scale = m('scale'); foreach (array_keys($scale->thumnails_sizes) as $folder) { // Form image path for scale module $imageScalePath = $path . $folder . '/' . $src; if ($fsModule->exists($imageScalePath)) { $fsModule->delete($imageScalePath); } } } $fsModule->delete($file); // Save empty field value $this->field->save(''); return array('status' => true); }
function display() { $search = trim(optional_param('search', '', PARAM_TEXT)); $alpha = optional_param('alpha', '', PARAM_ALPHA); // TODO: with a little more work, we could keep the previously selected sort here $params = $_GET; unset($params['page']); // We want to go back to the first page unset($params['search']); // And clear the search $target = $this->page->get_new_page($params); echo "<table class=\"searchbox\" style=\"margin-left:auto;margin-right:auto\" cellpadding=\"10\"><tr><td>"; echo "<form action=\"" . $target->get_url() . "\" method=\"post\">"; echo "<fieldset class=\"invisiblefieldset\">"; echo "<input type=\"text\" name=\"search\" value=\"" . s($search, true) . "\" size=\"20\" />"; echo '<input type="submit" value="' . get_string('search') . '" />'; //remove the "bare" parameter to prevent from loading only part of the page $moodleurl = new moodle_url($target->get_url()); $moodleurl->remove_params('mode'); if ($search) { echo "<input type=\"button\" onclick=\"document.location='" . $moodleurl->out() . "';\" " . "value=\"Show all items\" />"; } echo "</fieldset></form>"; echo "</td></tr></table>"; }
function display_search_field($value = '') { global $CFG; if (is_array($value)) { $content = $value['checked']; $allrequired = $value['allrequired'] ? 'checked = "checked"' : ''; } else { $content = array(); $allrequired = ''; } static $c = 0; $str = ''; $found = false; foreach (explode("\n", $this->field->param1) as $checkbox) { $checkbox = trim($checkbox); $str .= '<input type="checkbox" value="' . s($checkbox) . '"'; if (in_array(addslashes($checkbox), $content)) { // Selected by user. $str .= ' checked = "checked"'; } $str .= 'name="f_' . $this->field->id . '[]">' . $checkbox . '<br />'; $found = true; } if (!$found) { // oh, nothing to search for return ''; } $str .= ' <input name="f_' . $this->field->id . '_allreq" id="f_' . $this->field->id . '_allreq' . $c . '" type="checkbox" ' . $allrequired . '/>'; $str .= '<label for="f_' . $this->field->id . '_allreq' . $c . '">' . get_string('selectedrequired', 'data') . '</label>'; $c++; return $str; }
/** * routing * * @since 1.2.1 * @deprecated 2.0.0 * * @package Redaxscript * @category Center * @author Henry Ruhs */ function routing() { /* check token */ if ($_POST && $_POST['token'] != TOKEN) { notification(l('error_occurred'), l('token_incorrect'), l('home'), ROOT); return; } /* call default post */ $post_list = array('comment', 'login', 'password_reset', 'registration', 'reminder', 'search'); foreach ($post_list as $value) { if ($_POST[$value . '_post'] && function_exists($value . '_post')) { call_user_func($value . '_post'); return; } } /* general routing */ switch (FIRST_PARAMETER) { case 'admin': if (LOGGED_IN == TOKEN) { admin_routing(); } else { notification(l('error_occurred'), l('access_no'), l('login'), 'login'); } return; case 'login': login_form(); return; case 'logout': if (LOGGED_IN == TOKEN) { logout(); } else { notification(l('error_occurred'), l('access_no'), l('login'), 'login'); } return; case 'password_reset': if (s('reminder') == 1 && FIRST_SUB_PARAMETER && THIRD_PARAMETER) { password_reset_form(); } else { notification(l('error_occurred'), l('access_no'), l('home'), ROOT); } return; case 'registration': if (s('registration')) { registration_form(); } else { notification(l('error_occurred'), l('access_no'), l('home'), ROOT); } return; case 'reminder': if (s('reminder') == 1) { reminder_form(); } else { notification(l('error_occurred'), l('access_no'), l('home'), ROOT); } return; default: contents(); return; } }
/** * @param $callable * * @throws InvalidResolverException */ public function setResolver($callable) { if (!is_callable($callable)) { throw new InvalidResolverException(s('Routing resolver must be a callable, received "%s".', get_type($callable))); } $this->resolver = $callable; }
/** * execute tests */ public function test($action, $context) { $action = us($action); // create token generator object $generator = $context->createObject('simple', 'token_generator'); switch ($action) { case "simple_default": // create token generator object $token = $generator->generateToken(); $this->assertEquals(strlen($token), 40); $this->assertEquals(preg_match("/[^0-9a-zA-Z]+/", $token), false); echo "default token: {$token}"; break; case "simple_sha1": $config = new Charcoal_Config($this->getSandbox()->getEnvironment()); $config->set(s('algorithm'), 'sha1'); $generator->configure($config); $token = $generator->generateToken(); $this->assertEquals(strlen($token), 40); $this->assertEquals(preg_match("/[^0-9a-zA-Z]+/", $token), false); echo "sha1 token: {$token}"; break; case "simple_md5": $config = new Charcoal_Config($this->getSandbox()->getEnvironment()); $config->set(s('algorithm'), 'md5'); $generator->configure($config); $token = $generator->generateToken(); $this->assertEquals(strlen($token), 32); $this->assertEquals(preg_match("/[^0-9a-zA-Z]+/", $token), false); echo "md5 token: {$token}"; break; } }
function print_student_answer($userid, $return=false){ global $CFG, $USER, $OUTPUT; $fs = get_file_storage(); $browser = get_file_browser(); $output = ''; if ($submission = $this->get_submission($userid)) { if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) { foreach ($files as $file) { $filename = $file->get_filename(); $found = true; $mimetype = $file->get_mimetype(); $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename); $output .= '<a href="'.$path.'" >'.$OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')).s($filename).'</a><br />'; $output .= plagiarism_get_links(array('userid'=>$userid, 'file'=>$file, 'cmid'=>$this->cm->id, 'course'=>$this->course, 'assignment'=>$this->assignment)); $output .='<br/>'; } } } $output = '<div class="files">'.$output.'</div>'; return $output; }
function display_add_field($recordid = 0, $formdata = null) { global $DB, $OUTPUT; if ($formdata) { $fieldname = 'field_' . $this->field->id . '_day'; $day = $formdata->{$fieldname}; $fieldname = 'field_' . $this->field->id . '_month'; $month = $formdata->{$fieldname}; $fieldname = 'field_' . $this->field->id . '_year'; $year = $formdata->{$fieldname}; $calendartype = \core_calendar\type_factory::get_calendar_instance(); $gregoriandate = $calendartype->convert_to_gregorian($year, $month, $day); $content = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], $gregoriandate['minute'], 0, 0, false); } else { if ($recordid) { $content = (int) $DB->get_field('data_content', 'content', array('fieldid' => $this->field->id, 'recordid' => $recordid)); } else { $content = time(); } } $str = '<div title="' . s($this->field->description) . '" class="mod-data-input">'; $dayselector = html_writer::select_time('days', 'field_' . $this->field->id . '_day', $content); $monthselector = html_writer::select_time('months', 'field_' . $this->field->id . '_month', $content); $yearselector = html_writer::select_time('years', 'field_' . $this->field->id . '_year', $content); $str .= $dayselector . $monthselector . $yearselector; $str .= '</div>'; return $str; }
/** * Returns course details in an array ready to be printed. * * @global \moodle_database $DB * @param \course_in_list $course * @return array */ public static function get_course_detail_array(\course_in_list $course) { global $DB; $canaccess = $course->can_access(); $format = \course_get_format($course->id); $modinfo = \get_fast_modinfo($course->id); $modules = $modinfo->get_used_module_names(); $sections = array(); if ($format->uses_sections()) { foreach ($modinfo->get_section_info_all() as $section) { if ($section->uservisible) { $sections[] = $format->get_section_name($section); } } } $category = \coursecat::get($course->category); $categoryurl = new \moodle_url('/course/management.php', array('categoryid' => $course->category)); $categoryname = $category->get_formatted_name(); $details = array('fullname' => array('key' => \get_string('fullname'), 'value' => $course->get_formatted_fullname()), 'shortname' => array('key' => \get_string('shortname'), 'value' => $course->get_formatted_shortname()), 'idnumber' => array('key' => \get_string('idnumber'), 'value' => s($course->idnumber)), 'category' => array('key' => \get_string('category'), 'value' => \html_writer::link($categoryurl, $categoryname))); if (has_capability('moodle/site:accessallgroups', $course->get_context())) { $groups = \groups_get_course_data($course->id); $details += array('groupings' => array('key' => \get_string('groupings', 'group'), 'value' => count($groups->groupings)), 'groups' => array('key' => \get_string('groups'), 'value' => count($groups->groups))); } if ($canaccess) { $names = \role_get_names($course->get_context()); $sql = 'SELECT ra.roleid, COUNT(ra.id) AS rolecount FROM {role_assignments} ra WHERE ra.contextid = :contextid GROUP BY ra.roleid'; $rolecounts = $DB->get_records_sql($sql, array('contextid' => $course->get_context()->id)); $roledetails = array(); foreach ($rolecounts as $result) { $a = new \stdClass(); $a->role = $names[$result->roleid]->localname; $a->count = $result->rolecount; $roledetails[] = \get_string('assignedrolecount', 'moodle', $a); } $details['roleassignments'] = array('key' => \get_string('roleassignments'), 'value' => join('<br />', $roledetails)); } if ($course->can_review_enrolments()) { $enrolmentlines = array(); $instances = \enrol_get_instances($course->id, true); $plugins = \enrol_get_plugins(true); foreach ($instances as $instance) { if (!isset($plugins[$instance->enrol])) { // Weird. continue; } $plugin = $plugins[$instance->enrol]; $enrolmentlines[] = $plugin->get_instance_name($instance); } $details['enrolmentmethods'] = array('key' => \get_string('enrolmentmethods'), 'value' => join('<br />', $enrolmentlines)); } if ($canaccess) { $details['format'] = array('key' => \get_string('format'), 'value' => \course_get_format($course)->get_format_name()); $details['sections'] = array('key' => \get_string('sections'), 'value' => join('<br />', $sections)); $details['modulesused'] = array('key' => \get_string('modulesused'), 'value' => join('<br />', $modules)); } return $details; }
/** * @return string */ public function getMessage() { if ($this->message !== null) { return $this->message; } return s('Contains not allowed values, forbidden values are "%s".', implode(', ', $this->forbidden)); }
function display_add_field($recordid = 0) { global $CFG; $content = array(); if ($recordid) { $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid); $content = explode('##', $content); } $str = '<div title="' . s($this->field->description) . '">'; $str .= '<fieldset><legend><span class="accesshide">' . $this->field->name . '</span></legend>'; $i = 0; foreach (explode("\n", $this->field->param1) as $checkbox) { $checkbox = trim($checkbox); if ($checkbox === '') { continue; // skip empty lines } $str .= '<input type="checkbox" id="field_' . $this->field->id . '_' . $i . '" name="field_' . $this->field->id . '[]" '; $str .= 'value="' . s($checkbox) . '" '; if (array_search($checkbox, $content) !== false) { $str .= 'checked />'; } else { $str .= '/>'; } $str .= '<label for="field_' . $this->field->id . '_' . $i . '">' . $checkbox . '</label><br />'; $i++; } $str .= '</fieldset>'; $str .= '</div>'; return $str; }
function display_add_field($recordid = 0, $formdata = null) { global $DB, $OUTPUT; if ($formdata) { $fieldname = 'field_' . $this->field->id . '_day'; $day = $formdata->{$fieldname}; $fieldname = 'field_' . $this->field->id . '_month'; $month = $formdata->{$fieldname}; $fieldname = 'field_' . $this->field->id . '_year'; $year = $formdata->{$fieldname}; $content = make_timestamp($year, $month, $day, 12, 0, 0, 0, false); } else { if ($recordid) { $content = (int) $DB->get_field('data_content', 'content', array('fieldid' => $this->field->id, 'recordid' => $recordid)); } else { $content = time(); } } $str = '<div title="' . s($this->field->description) . '" class="mod-data-input">'; $dayselector = html_writer::select_time('days', 'field_' . $this->field->id . '_day', $content); $monthselector = html_writer::select_time('months', 'field_' . $this->field->id . '_month', $content); $yearselector = html_writer::select_time('years', 'field_' . $this->field->id . '_year', $content); $str .= $dayselector . $monthselector . $yearselector; $str .= '</div>'; return $str; }
/** * Returns table name * * @return string */ public function getTableName() { if (!property_exists($this, '___table_name')) { _throw(new Charcoal_TableModelException($this, s('___table_name property is not set'))); } return $this->___table_name; }
function display_add_field($recordid = 0, $formdata = null) { global $CFG, $DB, $OUTPUT, $PAGE; require_once $CFG->dirroot . '/repository/lib.php'; // necessary for the constants used in args $args = new stdClass(); $args->accepted_types = '*'; $args->return_types = FILE_EXTERNAL; $args->context = $this->context; $args->env = 'url'; $fp = new file_picker($args); $options = $fp->options; $fieldid = 'field_url_' . $options->client_id; $straddlink = get_string('choosealink', 'repository'); $url = ''; $text = ''; if ($formdata) { $fieldname = 'field_' . $this->field->id . '_0'; $url = $formdata->{$fieldname}; $fieldname = 'field_' . $this->field->id . '_1'; if (isset($formdata->{$fieldname})) { $text = $formdata->{$fieldname}; } } else { if ($recordid) { if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) { $url = $content->content; $text = $content->content1; } } } $str = '<div title="' . s($this->field->description) . '">'; $label = '<label for="' . $fieldid . '"><span class="accesshide">' . $this->field->name . '</span>'; if ($this->field->required) { $label .= html_writer::img($OUTPUT->pix_url('req'), get_string('requiredelement', 'form'), array('class' => 'req', 'title' => get_string('requiredelement', 'form'))); } $label .= '</label>'; if (!empty($this->field->param1) and empty($this->field->param2)) { $str .= '<table><tr><td align="right">'; $str .= get_string('url', 'data') . ':</td><td>'; $str .= $label; $str .= '<input type="text" name="field_' . $this->field->id . '_0" id="' . $fieldid . '" value="' . $url . '" size="60" />'; $str .= '<button id="filepicker-button-' . $options->client_id . '" style="display:none">' . $straddlink . '</button></td></tr>'; $str .= '<tr><td align="right">' . get_string('text', 'data') . ':</td><td><input type="text" name="field_' . $this->field->id . '_1" id="field_' . $this->field->id . '_1" value="' . s($text) . '" size="60" /></td></tr>'; $str .= '</table>'; } else { // Just the URL field $str .= $label; $str .= '<input type="text" name="field_' . $this->field->id . '_0" id="' . $fieldid . '" value="' . s($url) . '" size="60" />'; if (count($options->repositories) > 0) { $str .= '<button id="filepicker-button-' . $options->client_id . '" class="visibleifjs">' . $straddlink . '</button>'; } } // print out file picker //$str .= $OUTPUT->render($fp); $module = array('name' => 'data_urlpicker', 'fullpath' => '/mod/data/data.js', 'requires' => array('core_filepicker')); $PAGE->requires->js_init_call('M.data_urlpicker.init', array($options), true, $module); $str .= '</div>'; return $str; }
public function __construct(\samson\cms\CMSMaterial &$parent, $locale = 'ru') { $this->dbQuery = new dbQuery(); // Retrieve pointer to current module for rendering $this->renderModule =& s()->module($this->renderModule); $this->locale = $locale; // Save pointer to CMSMaterial $this->parent =& $parent; // Get all child materials identifiers from parent $materialIDs = dbQuery('material')->cond('material.parent_id', $this->parent->id)->cond('material.Active', 1)->cond('material.Draft', 0)->fields('MaterialID'); // Iterate all parent material structures foreach ($parent->cmsnavs() as $structure) { // Use only special structures if (isset($structure->type) && $structure->type == 1) { //$this->structures[$structure->id] = $structure; // Iterate all fields foreach ($structure->fields() as $field) { // Use only localizable fields if ($locale != '' && $field->local == 1 && !isset($this->fields[$field->id])) { // Gather key => value fields collection $this->fields[$field->id] = $field; // Iterate all child materials foreach ($materialIDs as $materialID) { // Check if they already have this material field if (!dbQuery('materialfield')->MaterialID($materialID)->locale($this->locale)->FieldID($field->id)->first()) { // Create material field record $mf = new \samson\activerecord\materialfield(false); $mf->MaterialID = $materialID; $mf->FieldID = $field->id; $mf->Active = 1; $mf->locale = $this->locale; $mf->save(); } } } else { if ($locale == '' && $field->local == 0 && !isset($this->fields[$field->id])) { // Gather key => value fields collection $this->fields[$field->id] = $field; // Iterate all child materials foreach ($materialIDs as $materialID) { // Check if they already have this material field if (!dbQuery('materialfield')->MaterialID($materialID)->locale($this->locale)->FieldID($field->id)->first()) { // Create material field record $mf = new \samson\activerecord\materialfield(false); $mf->MaterialID = $materialID; $mf->FieldID = $field->id; $mf->Active = 1; $mf->save(); } } } } } } } // Get all child materials material fields for this locale $this->query = dbQuery('material')->parent_id($this->parent->id)->join('materialfield')->cond('materialfield_FieldID', array_keys($this->fields))->cond('materialfield_locale', $this->locale); // Constructor treed parent::__construct($this->query); }
function user_create($Username, $Password) { global $pdo; if (user_exists($Username)) { return false; } $stmt = $pdo->prepare(' INSERT INTO `users` ( `username` , `password` ) VALUES ( :username , :password )'); $stmt->bindValue(':username', s($Username)); $stmt->bindValue(':password', user_hash($Password, $Username)); $stmt->execute(); $uid = $pdo->lastInsertId(); $stmt->closeCursor(); // Create a group for the new user lib('Group'); $gid = group_create(s($Username), 'user'); group_add($gid, $uid); return $uid; }
function definition() { $mform =& $this->_form; $mnet_peer =& $this->_customdata['peer']; $myservices =& mnet_get_service_info($mnet_peer); $mform->addElement('hidden', 'hostid', $mnet_peer->id); $count = 0; foreach ($myservices as $name => $versions) { $version = current($versions); $langmodule = ($version['plugintype'] == 'mod' ? '' : $version['plugintype'] . '_') . $version['pluginname']; // TODO there should be a moodle-wide way to do this if ($count > 0) { $mform->addElement('html', '<hr />'); } $mform->addElement('html', '<h3>' . get_string($name . '_name', $langmodule, $mnet_peer->name) . '</h3>' . get_string($name . '_description', $langmodule, $mnet_peer->name)); $mform->addElement('hidden', 'exists[' . $version['serviceid'] . ']', 1); $pubstr = get_string('publish', 'mnet'); if (!empty($version['hostsubscribes'])) { $pubstr .= ' <a class="notifysuccess" title="' . s(get_string('issubscribed', 'mnet', $mnet_peer->name)) . '">√</a> '; } $mform->addElement('advcheckbox', 'publish[' . $version['serviceid'] . ']', $pubstr); $substr = get_string('subscribe', 'mnet'); if (!empty($version['hostpublishes'])) { $substr .= ' <a class="notifysuccess" title="' . s(get_string('ispublished', 'mnet', $mnet_peer->name)) . '">√</a> '; } $mform->addElement('advcheckbox', 'subscribe[' . $version['serviceid'] . ']', $substr); $count++; } $this->add_action_buttons(); }
function display_add_field($recordid = 0, $formdata = null) { global $DB, $OUTPUT; if ($formdata) { $fieldname = 'field_' . $this->field->id; $content = $formdata->{$fieldname}; } else { if ($recordid) { $content = $DB->get_field('data_content', 'content', array('fieldid' => $this->field->id, 'recordid' => $recordid)); $content = trim($content); } else { $content = ''; } } $str = '<div title="' . s($this->field->description) . '">'; $options = array(); $rawoptions = explode("\n", $this->field->param1); foreach ($rawoptions as $option) { $option = trim($option); if (strlen($option) > 0) { $options[$option] = $option; } } $str .= '<label for="' . 'field_' . $this->field->id . '">'; $str .= html_writer::span($this->field->name, 'accesshide'); if ($this->field->required) { $image = html_writer::img($OUTPUT->pix_url('req'), get_string('requiredelement', 'form'), array('class' => 'req', 'title' => get_string('requiredelement', 'form'))); $str .= html_writer::div($image, 'inline-req'); } $str .= '</label>'; $str .= html_writer::select($options, 'field_' . $this->field->id, $content, array('' => get_string('menuchoose', 'data')), array('id' => 'field_' . $this->field->id, 'class' => 'mod-data-input custom-select')); $str .= '</div>'; return $str; }
public function __construct() { $this->coderoot = dirname(__FILE__) . '/MessageStatisticsPlugin/'; $this->version = is_file($f = $this->coderoot . self::VERSION_FILE) ? file_get_contents($f) : ''; $this->settings = array('statistics_export_all_messages' => array('value' => true, 'description' => s("On the Campaigns tab, whether to export all campaigns. If 'No' then only those currently listed will be exported."), 'type' => 'boolean', 'allowempty' => true, 'category' => 'Campaign Statistics')); parent::__construct(); }
function display_add_field($recordid = 0) { if ($recordid) { $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid); $content = explode('##', $content); } else { $content = array(); } $str = '<div title="' . s($this->field->description) . '">'; $str .= '<select name="field_' . $this->field->id . '[]" id="field_' . $this->field->id . '" multiple="multiple">'; foreach (explode("\n", $this->field->param1) as $option) { $option = trim($option); $str .= '<option value="' . s($option) . '"'; if (array_search($option, $content) !== false) { // Selected by user. $str .= ' selected >'; } else { $str .= '>'; } $str .= $option . '</option>'; } $str .= '</select>'; $str .= '</div>'; return $str; }
function display_add_field($recordid = 0) { global $CFG; $url = ''; $text = ''; if ($recordid) { if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { $url = $content->content; $text = $content->content1; } } $url = empty($url) ? 'http://' : $url; $str = '<div title="' . s($this->field->description) . '">'; if (!empty($this->field->param1) and empty($this->field->param2)) { $str .= '<table><tr><td align="right">'; $str .= get_string('url', 'data') . ':</td><td><input type="text" name="field_' . $this->field->id . '_0" id="field_' . $this->field->id . '_0" value="' . $url . '" size="60" /></td></tr>'; $str .= '<tr><td align="right">' . get_string('text', 'data') . ':</td><td><input type="text" name="field_' . $this->field->id . '_1" id="field_' . $this->field->id . '_1" value="' . s($text) . '" size="60" /></td></tr>'; $str .= '</table>'; } else { // Just the URL field $str .= '<input type="text" name="field_' . $this->field->id . '_0" id="field_' . $this->field->id . '_0" value="' . s($url) . '" size="60" />'; } $str .= '</div>'; return $str; }
/** * Internal function - creates htmls structure suitable for YUI tree. */ protected function htmllize_tree($tree, $dir) { global $CFG; if (empty($dir['subdirs']) and empty($dir['files'])) { return ''; } $result = '<ul>'; foreach ($dir['subdirs'] as $subdir) { $image = $this->output->pix_icon(file_folder_icon(24), $subdir['dirname'], 'moodle'); $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', s($subdir['dirname']), array('class' => 'fp-filename')); $filename = html_writer::tag('div', $filename, array('class' => 'fp-filename-icon')); $result .= html_writer::tag('li', $filename. $this->htmllize_tree($tree, $subdir)); } foreach ($dir['files'] as $file) { $filename = $file->get_filename(); $url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $filename, false); if (file_extension_in_typegroup($filename, 'web_image')) { $image = $url->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified())); $image = html_writer::empty_tag('img', array('src' => $image)); } else { $image = $this->output->pix_icon(file_file_icon($file, 24), $filename, 'moodle'); } $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', $filename, array('class' => 'fp-filename')); $filename = html_writer::tag('span', html_writer::link($url->out(false, array('forcedownload' => 1)), $filename), array('class' => 'fp-filename-icon')); $result .= html_writer::tag('li', $filename); } $result .= '</ul>'; return $result; }